PredisStore::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
nc 2
cc 2
eloc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the webmozart/key-value-store package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webmozart\KeyValueStore;
13
14
use Predis\Client;
15
use Predis\ClientInterface;
16
17
/**
18
 * A key-value store that uses Predis to connect to a Redis instance.
19
 *
20
 * @since  1.0
21
 *
22
 * @author Bernhard Schussek <[email protected]>
23
 * @author Titouan Galopin <[email protected]>
24
 */
25
class PredisStore extends AbstractRedisStore
26
{
27
    /**
28
     * Creates a store backed by a Predis client.
29
     *
30
     * If no client is passed, a new one is created using the default server
31
     * "127.0.0.1" and the default port 6379.
32
     *
33
     * @param ClientInterface|null $client The client used to connect to Redis.
34
     */
35 82
    public function __construct(ClientInterface $client = null)
36
    {
37 82
        $this->client = $client ?: new Client();
38 82
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 39
    protected function clientNotFoundValue()
44
    {
45 39
        return null;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 35
    protected function clientGet($key)
52
    {
53 35
        return $this->client->get($key);
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 34
    protected function clientGetMultiple(array $keys)
60
    {
61 34
        return $this->client->mget($keys);
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 54
    protected function clientSet($key, $value)
68
    {
69 54
        $this->client->set($key, $value);
70 53
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 8
    protected function clientRemove($key)
76
    {
77 8
        return (bool) $this->client->del($key);
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 29
    protected function clientExists($key)
84
    {
85 29
        return (bool) $this->client->exists($key);
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 82
    protected function clientClear()
92
    {
93 82
        $this->client->flushdb();
94 82
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 4
    protected function clientKeys()
100
    {
101 4
        return $this->client->keys('*');
102
    }
103
}
104