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 Redis; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* A key-value store that uses the PhpRedis extension to connect to a Redis instance. |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
* |
21
|
|
|
* @author Bernhard Schussek <[email protected]> |
22
|
|
|
* @author Philipp Wahala <[email protected]> |
23
|
|
|
* @author Titouan Galopin <[email protected]> |
24
|
|
|
* |
25
|
|
|
* @link https://github.com/phpredis/phpredis |
26
|
|
|
*/ |
27
|
|
|
class PhpRedisStore extends AbstractRedisStore |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Creates a store backed by a PhpRedis client. |
31
|
|
|
* |
32
|
|
|
* If no client is passed, a new one is created using the default server |
33
|
|
|
* "127.0.0.1" and the default port 6379. |
34
|
|
|
* |
35
|
|
|
* @param Redis|null $client The client used to connect to Redis. |
36
|
|
|
*/ |
37
|
82 |
|
public function __construct(Redis $client = null) |
38
|
|
|
{ |
39
|
82 |
|
if (null === $client) { |
40
|
82 |
|
$client = new Redis(); |
41
|
82 |
|
$client->connect('127.0.0.1', 6379); |
42
|
|
|
} |
43
|
|
|
|
44
|
82 |
|
$this->client = $client; |
45
|
82 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
39 |
|
protected function clientNotFoundValue() |
51
|
|
|
{ |
52
|
39 |
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* {@inheritdoc} |
57
|
|
|
*/ |
58
|
35 |
|
protected function clientGet($key) |
59
|
|
|
{ |
60
|
35 |
|
return $this->client->get($key); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* {@inheritdoc} |
65
|
|
|
*/ |
66
|
34 |
|
protected function clientGetMultiple(array $keys) |
67
|
|
|
{ |
68
|
34 |
|
return $this->client->getMultiple($keys); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* {@inheritdoc} |
73
|
|
|
*/ |
74
|
54 |
|
protected function clientSet($key, $value) |
75
|
|
|
{ |
76
|
54 |
|
$this->client->set($key, $value); |
77
|
53 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* {@inheritdoc} |
81
|
|
|
*/ |
82
|
8 |
|
protected function clientRemove($key) |
83
|
|
|
{ |
84
|
8 |
|
return (bool) $this->client->del($key); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* {@inheritdoc} |
89
|
|
|
*/ |
90
|
29 |
|
protected function clientExists($key) |
91
|
|
|
{ |
92
|
29 |
|
return (bool) $this->client->exists($key); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* {@inheritdoc} |
97
|
|
|
*/ |
98
|
82 |
|
protected function clientClear() |
99
|
|
|
{ |
100
|
82 |
|
$this->client->flushdb(); |
101
|
82 |
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
4 |
|
protected function clientKeys() |
107
|
|
|
{ |
108
|
4 |
|
return $this->client->keys('*'); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|