1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Webdcg\Redis\Traits; |
4
|
|
|
|
5
|
|
|
trait Keys |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Remove specified keys [Blocking]. |
9
|
|
|
* |
10
|
|
|
* @param mixed $keys |
11
|
|
|
* |
12
|
|
|
* @return int Number of keys deleted |
13
|
|
|
*/ |
14
|
|
|
public function del(...$keys): int |
15
|
|
|
{ |
16
|
|
|
return $this->redis->del(...$keys); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Remove specified keys [Non Blocking]. |
21
|
|
|
* |
22
|
|
|
* @param mixed $keys |
23
|
|
|
* |
24
|
|
|
* @return int Number of keys deleted |
25
|
|
|
*/ |
26
|
|
|
public function delete(...$keys): int |
27
|
|
|
{ |
28
|
|
|
return $this->redis->unlink(...$keys); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Remove specified keys [NonBlocking]. |
33
|
|
|
* |
34
|
|
|
* Note: If you are connecting to Redis server >= 4.0.0 you can remove a |
35
|
|
|
* key with the unlink method in the exact same way you would use del. |
36
|
|
|
* The Redis unlink command is non-blocking and will perform the actual |
37
|
|
|
* deletion asynchronously. |
38
|
|
|
* |
39
|
|
|
* @param mixed $keys |
40
|
|
|
* |
41
|
|
|
* @return int Number of keys deleted |
42
|
|
|
*/ |
43
|
|
|
public function unlink(...$keys): int |
44
|
|
|
{ |
45
|
|
|
return $this->redis->unlink(...$keys); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Return a serialized version of the value stored at the specified key. |
50
|
|
|
* |
51
|
|
|
* @param string $key |
52
|
|
|
* |
53
|
|
|
* @return mixed|string|false The Redis encoded value of the key, |
54
|
|
|
* or FALSE if the key doesn't exist |
55
|
|
|
*/ |
56
|
|
|
public function dump(string $key) |
57
|
|
|
{ |
58
|
|
|
return $this->redis->dump($key); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Verify if the specified key exists. |
63
|
|
|
* |
64
|
|
|
* @param mixed] $keys |
|
|
|
|
65
|
|
|
* |
66
|
|
|
* @return int |
67
|
|
|
*/ |
68
|
|
|
public function exists(...$keys): int |
69
|
|
|
{ |
70
|
|
|
return $this->redis->exists(...$keys); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Sets an expiration date (a timeout) on an item. pexpire requires a TTL in milliseconds. |
75
|
|
|
* |
76
|
|
|
* @param string $key. The key that will disappear. |
|
|
|
|
77
|
|
|
* @param int $ttl. The key's remaining Time To Live, in seconds. |
|
|
|
|
78
|
|
|
* |
79
|
|
|
* @return bool true in case of success, false in case of failure. |
80
|
|
|
*/ |
81
|
|
|
public function expire(string $key, int $ttl): bool |
82
|
|
|
{ |
83
|
|
|
return $this->redis->expire($key, $ttl); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Sets an expiration date (a timeout) on an item. pexpire requires a TTL in milliseconds. |
88
|
|
|
* |
89
|
|
|
* @param string $key. The key that will disappear. |
|
|
|
|
90
|
|
|
* @param int $ttl. The key's remaining Time To Live, in seconds. |
|
|
|
|
91
|
|
|
* |
92
|
|
|
* @return bool true in case of success, false in case of failure. |
93
|
|
|
*/ |
94
|
|
|
public function setTimeout(string $key, int $ttl): bool |
95
|
|
|
{ |
96
|
|
|
return $this->redis->expire($key, $ttl); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Sets an expiration date (a timeout) on an item. pexpire requires a TTL in milliseconds. |
101
|
|
|
* |
102
|
|
|
* @param string $key. The key that will disappear. |
|
|
|
|
103
|
|
|
* @param int $ttl. The key's remaining Time To Live, in seconds. |
|
|
|
|
104
|
|
|
* |
105
|
|
|
* @return bool true in case of success, false in case of failure. |
106
|
|
|
*/ |
107
|
|
|
public function pexpire(string $key, int $ttl): bool |
108
|
|
|
{ |
109
|
|
|
return $this->redis->pexpire($key, $ttl); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Sets an expiration date (a timestamp) on an item. |
114
|
|
|
* |
115
|
|
|
* @param string $key The key that will disappear. |
116
|
|
|
* @param int $ttl Unix timestamp. The key's date of death, in seconds from Epoch time. |
117
|
|
|
* |
118
|
|
|
* @return bool true in case of success, false in case of failure. |
119
|
|
|
*/ |
120
|
|
|
public function expireAt(string $key, int $ttl): bool |
121
|
|
|
{ |
122
|
|
|
return $this->redis->expireAt($key, $ttl); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Sets an expiration date (a timestamp) on an item in milliseconds. |
127
|
|
|
* |
128
|
|
|
* @param string $key The key that will disappear. |
129
|
|
|
* @param int $ttl Unix timestamp. The key's date of death, in |
130
|
|
|
* milliseconds from Epoch time with. |
131
|
|
|
* |
132
|
|
|
* @return bool true in case of success, false in case of failure. |
133
|
|
|
*/ |
134
|
|
|
public function pexpireAt(string $key, int $ttl): bool |
135
|
|
|
{ |
136
|
|
|
return $this->redis->pexpireAt($key, $ttl); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Returns the keys that match a certain pattern. |
141
|
|
|
* |
142
|
|
|
* @param string $pattern Pattern to match, using '*' as a wildcard. |
143
|
|
|
* |
144
|
|
|
* @return array The keys that match a certain pattern. |
145
|
|
|
*/ |
146
|
|
|
public function keys(string $pattern): array |
147
|
|
|
{ |
148
|
|
|
return $this->redis->keys($pattern); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Returns the keys that match a certain pattern. |
153
|
|
|
* |
154
|
|
|
* @param string $pattern Pattern to match, using '*' as a wildcard. |
155
|
|
|
* |
156
|
|
|
* @return array The keys that match a certain pattern. |
157
|
|
|
*/ |
158
|
|
|
public function getKeys(string $pattern): array |
159
|
|
|
{ |
160
|
|
|
return $this->redis->keys($pattern); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function scan(): bool |
164
|
|
|
{ |
165
|
|
|
return false; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function migrate(): bool |
169
|
|
|
{ |
170
|
|
|
return false; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function move(): bool |
174
|
|
|
{ |
175
|
|
|
return false; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
public function object(): bool |
179
|
|
|
{ |
180
|
|
|
return false; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function persist(): bool |
184
|
|
|
{ |
185
|
|
|
return false; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function randomKey(): bool |
189
|
|
|
{ |
190
|
|
|
return false; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function rename(): bool |
194
|
|
|
{ |
195
|
|
|
return false; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function renameKey(): bool |
199
|
|
|
{ |
200
|
|
|
return false; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function renameNx(): bool |
204
|
|
|
{ |
205
|
|
|
return false; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
public function type(): bool |
209
|
|
|
{ |
210
|
|
|
return false; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
public function sort(): bool |
214
|
|
|
{ |
215
|
|
|
return false; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function ttl(): bool |
219
|
|
|
{ |
220
|
|
|
return false; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public function pttl(): bool |
224
|
|
|
{ |
225
|
|
|
return false; |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
public function restore(): bool |
229
|
|
|
{ |
230
|
|
|
return false; |
231
|
|
|
} |
232
|
|
|
} |
233
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: