1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dazzle\Redis\Command\Compose; |
4
|
|
|
|
5
|
|
|
use Dazzle\Redis\Command\Builder; |
6
|
|
|
use Dazzle\Redis\Command\Enum; |
7
|
|
|
use Dazzle\Redis\Driver\Request; |
8
|
|
|
|
9
|
|
|
trait ApiSetSortedTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param Request $request |
13
|
|
|
* @return mixed |
14
|
|
|
*/ |
15
|
|
|
abstract function dispatch(Request $request); |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @override |
19
|
|
|
* @inheritDoc |
20
|
|
|
*/ |
21
|
16 |
View Code Duplication |
public function zAdd($key, array $options = [], ...$scoreMembers) |
|
|
|
|
22
|
|
|
{ |
23
|
16 |
|
$command = Enum::ZADD; |
24
|
16 |
|
$args = array_merge([$key], $options, $scoreMembers); |
25
|
|
|
|
26
|
16 |
|
return $this->dispatch(Builder::build($command, $args)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @override |
31
|
|
|
* @inheritDoc |
32
|
|
|
*/ |
33
|
1 |
View Code Duplication |
public function zCard($key) |
|
|
|
|
34
|
|
|
{ |
35
|
1 |
|
$command = Enum::ZCARD; |
36
|
1 |
|
$args = [$key]; |
37
|
|
|
|
38
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @override |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
1 |
View Code Duplication |
public function zCount($key, $min, $max) |
|
|
|
|
46
|
|
|
{ |
47
|
1 |
|
$command = Enum::ZCOUNT; |
48
|
1 |
|
$args = [$key, $min, $max]; |
49
|
|
|
|
50
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @override |
55
|
|
|
* @inheritDoc |
56
|
|
|
*/ |
57
|
1 |
|
public function zIncrBy($key, $increment, $member) |
58
|
|
|
{ |
59
|
1 |
|
$command = Enum::ZINCRBY; |
60
|
1 |
|
$args = [$key, $increment, $member]; |
61
|
|
|
|
62
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @override |
67
|
|
|
* @inheritDoc |
68
|
|
|
*/ |
69
|
|
|
public function zInterStore($dst, $numKeys) |
70
|
|
|
{ |
71
|
|
|
// TODO: Implement zInterStore() method. |
72
|
|
|
$command = Enum::ZINTERSTORE; |
73
|
|
|
$args = [$dst, $numKeys]; |
74
|
|
|
|
75
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @override |
80
|
|
|
* @inheritDoc |
81
|
|
|
*/ |
82
|
1 |
View Code Duplication |
public function zLexCount($key, $min, $max) |
|
|
|
|
83
|
|
|
{ |
84
|
1 |
|
$command = Enum::ZLEXCOUNT; |
85
|
1 |
|
$args = [$key, $min, $max]; |
86
|
|
|
|
87
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @override |
92
|
|
|
* @inheritDoc |
93
|
|
|
*/ |
94
|
1 |
|
public function zRange($key, $star = 0, $stop = -1, $withScores = false) |
95
|
|
|
{ |
96
|
1 |
|
$command = Enum::ZRANGE; |
97
|
1 |
|
$args = [$key, $star, $stop]; |
98
|
1 |
|
if ($withScores) { |
99
|
1 |
|
$args[] = 'WITHSCORES'; |
100
|
|
|
return $this->dispatch(Builder::build($command, $args))->then(function ($value) { |
101
|
1 |
|
$len = count($value); |
102
|
1 |
|
$ret = []; |
103
|
1 |
|
for ($i=0; $i<$len; $i+=2) { |
104
|
1 |
|
$ret[$value[$i]] = $value[$i+1]; |
105
|
|
|
} |
106
|
1 |
|
return $ret; |
107
|
1 |
|
}); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @override |
115
|
|
|
* @inheritDoc |
116
|
|
|
*/ |
117
|
1 |
|
public function zRangeByLex($key, $min, $max, array $options = []) |
118
|
|
|
{ |
119
|
1 |
|
$command = Enum::ZRANGEBYLEX; |
120
|
1 |
|
$args = [$key, $min, $max]; |
121
|
1 |
|
$args = array_merge($args, $options); |
122
|
|
|
|
123
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @override |
128
|
|
|
* @inheritDoc |
129
|
|
|
*/ |
130
|
1 |
|
public function zRevRangeByLex($key, $max, $min, array $options = []) |
131
|
|
|
{ |
132
|
1 |
|
$command = Enum::ZREVRANGEBYLEX; |
133
|
1 |
|
$args = [$key, $max,$min]; |
134
|
1 |
|
$args = array_merge($args,$options); |
135
|
|
|
|
136
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @override |
141
|
|
|
* @inheritDoc |
142
|
|
|
*/ |
143
|
1 |
View Code Duplication |
public function zRangeByScore($key, $min, $max, $withScores = false, $offset = 0, $count = 0) |
|
|
|
|
144
|
|
|
{ |
145
|
1 |
|
$command = Enum::ZRANGEBYSCORE; |
146
|
1 |
|
$args = [$key, $min, $max]; |
147
|
1 |
|
if ($withScores === true) { |
148
|
1 |
|
$args[] = 'WITHSCORES'; |
149
|
|
|
} |
150
|
1 |
|
if ($offset != 0 || $count != 0) { |
151
|
1 |
|
$args[] = 'LIMIT'; |
152
|
1 |
|
$args[] = $offset; |
153
|
1 |
|
$args[] = $count; |
154
|
|
|
} |
155
|
1 |
|
$promise = $this->dispatch(Builder::build($command, $args)); |
156
|
|
|
|
157
|
|
|
return $withScores ? $promise->then(function ($value) { |
158
|
1 |
|
$len = is_array($value) ? count($value) : 0; |
159
|
1 |
|
if ($len > 0) { |
160
|
1 |
|
$ret = []; |
161
|
1 |
|
for ($i=0; $i<$len; $i+=2) { |
162
|
1 |
|
$ret[$value[$i]] = $value[$i+1]; |
163
|
|
|
} |
164
|
|
|
|
165
|
1 |
|
return $ret; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return $value; |
169
|
1 |
|
} ) : $promise; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @override |
174
|
|
|
* @inheritDoc |
175
|
|
|
*/ |
176
|
1 |
|
public function zRank($key, $member) |
177
|
|
|
{ |
178
|
1 |
|
$command = Enum::ZRANK; |
179
|
1 |
|
$args = [$key,$member]; |
180
|
|
|
|
181
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @override |
186
|
|
|
* @inheritDoc |
187
|
|
|
*/ |
188
|
1 |
|
public function zRem($key, ...$members) |
189
|
|
|
{ |
190
|
1 |
|
$command = Enum::ZREM; |
191
|
1 |
|
$args = [$key]; |
192
|
1 |
|
$args = array_merge($args, $members); |
193
|
|
|
|
194
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @override |
199
|
|
|
* @inheritDoc |
200
|
|
|
*/ |
201
|
1 |
|
public function zRemRangeByLex($key, $min, $max, array $options = []) |
202
|
|
|
{ |
203
|
1 |
|
$command = Enum::ZREMRANGEBYLEX; |
204
|
1 |
|
$args = [$key, $min, $max]; |
205
|
1 |
|
$args = array_merge($args, $options); |
206
|
|
|
|
207
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @override |
212
|
|
|
* @inheritDoc |
213
|
|
|
*/ |
214
|
1 |
|
public function zRemRangeByRank($key, $start, $stop) |
215
|
|
|
{ |
216
|
1 |
|
$command = Enum::ZREMRANGEBYRANK; |
217
|
1 |
|
$args = [$key, $start,$stop]; |
218
|
|
|
|
219
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @override |
224
|
|
|
* @inheritDoc |
225
|
|
|
*/ |
226
|
1 |
|
public function zRemRangeByScore($key, $min, $max, array $options = []) |
227
|
|
|
{ |
228
|
1 |
|
$command = Enum::ZREMRANGEBYSCORE; |
229
|
1 |
|
$args = [$key, $min, $max]; |
230
|
1 |
|
$args = array_merge($args, $options); |
231
|
|
|
|
232
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @override |
237
|
|
|
* @inheritDoc |
238
|
|
|
*/ |
239
|
1 |
|
public function zRevRange($key, $start, $stop, $withScores = false) |
240
|
|
|
{ |
241
|
1 |
|
$command = Enum::ZREVRANGE; |
242
|
1 |
|
$args = [$key, $start, $stop]; |
243
|
|
|
|
244
|
1 |
|
if ($withScores === true) { |
245
|
1 |
|
$args[] = 'WITHSCORES'; |
246
|
|
|
|
247
|
1 |
|
return $this->dispatch(Builder::build($command, $args)) |
248
|
|
|
->then(function ($value) { |
249
|
1 |
|
$len = is_array($value) ? count($value) : 0; |
250
|
1 |
|
if ($len > 0) { |
251
|
1 |
|
$ret = []; |
252
|
1 |
|
for ($i=0; $i<$len; $i+=2) { |
253
|
1 |
|
$member = $value[$i]; |
254
|
1 |
|
$score = $value[$i+1]; |
255
|
1 |
|
$ret[$member] = $score; |
256
|
|
|
} |
257
|
|
|
|
258
|
1 |
|
return $ret; |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
return $value; |
262
|
1 |
|
}); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
return $promise = $this->dispatch(Builder::build($command, $args)); |
|
|
|
|
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* @override |
270
|
|
|
* @inheritDoc |
271
|
|
|
*/ |
272
|
1 |
View Code Duplication |
public function zRevRangeByScore($key, $max, $min, $withScores = false, $offset = 0, $count = 0) |
|
|
|
|
273
|
|
|
{ |
274
|
1 |
|
$command = Enum::ZREVRANGEBYSCORE; |
275
|
1 |
|
$args = [$key, $max, $min]; |
276
|
1 |
|
if ($withScores === true) { |
277
|
1 |
|
$args[] = 'WITHSCORES'; |
278
|
|
|
} |
279
|
1 |
|
if ($offset != 0 || $count != 0) { |
280
|
1 |
|
$args[] = 'LIMIT'; |
281
|
1 |
|
$args[] = $offset; |
282
|
1 |
|
$args[] = $count; |
283
|
|
|
} |
284
|
1 |
|
$promise = $this->dispatch(Builder::build($command, $args)); |
285
|
|
|
|
286
|
1 |
|
return $withScores ? $promise->then(function ($value) { |
287
|
1 |
|
$len = is_array($value) ? count($value) : 0; |
288
|
1 |
|
if ($len > 0) { |
289
|
1 |
|
$ret = []; |
290
|
1 |
|
for ($i=0; $i<$len; $i+=2) { |
291
|
1 |
|
$ret[$value[$i]] = $value[$i+1]; |
292
|
|
|
} |
293
|
|
|
|
294
|
1 |
|
return $ret; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
return $value; |
298
|
1 |
|
} ) : $promise; |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* @override |
303
|
|
|
* @inheritDoc |
304
|
|
|
*/ |
305
|
1 |
|
public function zRevRank($key, $member) |
306
|
|
|
{ |
307
|
1 |
|
$command = Enum::ZREVRANK; |
308
|
1 |
|
$args = [$key,$member]; |
309
|
|
|
|
310
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* @override |
315
|
|
|
* @inheritDoc |
316
|
|
|
*/ |
317
|
|
|
public function zScore($key, $member) |
318
|
|
|
{ |
319
|
|
|
$command = Enum::ZSCORE; |
320
|
|
|
$args = [$key,$member]; |
321
|
|
|
|
322
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @override |
327
|
|
|
* @inheritDoc |
328
|
|
|
*/ |
329
|
|
|
public function zScan($key, $cursor, array $options = []) |
330
|
|
|
{ |
331
|
|
|
// TODO: Implement zScan() method. |
332
|
|
|
$command = Enum::ZSCAN; |
333
|
|
|
$args = [$key , $cursor]; |
334
|
|
|
$args = array_merge($args, $options); |
335
|
|
|
|
336
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @inheritDoc |
341
|
|
|
*/ |
342
|
|
|
public function zUnionScore($dst, $numKeys) |
343
|
|
|
{ |
344
|
|
|
// TODO: Implement zUnionScore() method. |
345
|
|
|
$command = Enum::ZUNIIONSCORE; |
346
|
|
|
$args = [$dst, $numKeys]; |
347
|
|
|
|
348
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
349
|
|
|
} |
350
|
|
|
} |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.