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 ApiListTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* @param Request $request |
13
|
|
|
* @return mixed |
14
|
|
|
*/ |
15
|
|
|
abstract function dispatch(Request $request); |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @override |
19
|
|
|
* @inheritDoc |
20
|
|
|
*/ |
21
|
1 |
View Code Duplication |
public function blPop(array $keys, $timeout) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
// TODO: Implement blPop() method. |
24
|
1 |
|
$command = Enum::BLPOP; |
25
|
1 |
|
$keys[] = $timeout; |
26
|
1 |
|
$args = $keys; |
27
|
1 |
|
$promise = $this->dispatch(Builder::build($command, $args)); |
28
|
|
|
$promise = $promise->then(function ($value) { |
29
|
1 |
|
if (is_array($value)) { |
30
|
1 |
|
list($k,$v) = $value; |
31
|
|
|
|
32
|
|
|
return [ |
33
|
1 |
|
'key'=>$k, |
34
|
1 |
|
'value'=>$v |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $value; |
39
|
1 |
|
}); |
40
|
|
|
|
41
|
1 |
|
return $promise; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @override |
46
|
|
|
* @inheritDoc |
47
|
|
|
*/ |
48
|
1 |
View Code Duplication |
public function brPop(array $keys, $timeout) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
// TODO: Implement brPop() method. |
51
|
1 |
|
$command = Enum::BRPOP; |
52
|
1 |
|
$keys[] = $timeout; |
53
|
1 |
|
$args = $keys; |
54
|
1 |
|
$promise = $this->dispatch(Builder::build($command, $args)); |
55
|
1 |
|
$promise = $promise->then(function ($value) { |
56
|
1 |
|
if (is_array($value)) { |
57
|
1 |
|
list($k,$v) = $value; |
58
|
|
|
|
59
|
|
|
return [ |
60
|
1 |
|
'key'=>$k, |
61
|
1 |
|
'value'=>$v |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $value; |
66
|
1 |
|
}); |
67
|
|
|
|
68
|
1 |
|
return $promise; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @override |
73
|
|
|
* @inheritDoc |
74
|
|
|
*/ |
75
|
1 |
|
public function brPopLPush($src, $dst, $timeout) |
76
|
|
|
{ |
77
|
|
|
// TODO: Implement brPopLPush() method. |
78
|
1 |
|
$command = Enum::BRPOPLPUSH; |
79
|
1 |
|
$args = [$src, $dst, $timeout]; |
80
|
|
|
|
81
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @override |
86
|
|
|
* @inheritDoc |
87
|
|
|
*/ |
88
|
5 |
|
public function lIndex($key, $index) |
89
|
|
|
{ |
90
|
|
|
// TODO: Implement lIndex() method. |
91
|
5 |
|
$command = Enum::LINDEX; |
92
|
5 |
|
$args = [$key, $index]; |
93
|
|
|
|
94
|
5 |
|
return $this->dispatch(Builder::build($command, $args)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @override |
99
|
|
|
* @inheritDoc |
100
|
|
|
*/ |
101
|
1 |
|
public function lInsert($key, $action, $pivot, $value) |
102
|
|
|
{ |
103
|
|
|
// TODO: Implement lInsert() method. |
104
|
1 |
|
$command = Enum::LINSERT; |
105
|
1 |
|
$args = [$key, $action, $pivot, $value]; |
106
|
|
|
|
107
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @override |
112
|
|
|
* @inheritDoc |
113
|
|
|
*/ |
114
|
1 |
View Code Duplication |
public function lLen($key) |
|
|
|
|
115
|
|
|
{ |
116
|
|
|
// TODO: Implement lLen() method. |
117
|
1 |
|
$command = Enum::LLEN; |
118
|
1 |
|
$args = [$key]; |
119
|
|
|
|
120
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @override |
125
|
|
|
* @inheritDoc |
126
|
|
|
*/ |
127
|
1 |
View Code Duplication |
public function lPop($key) |
|
|
|
|
128
|
|
|
{ |
129
|
|
|
// TODO: Implement lPop() method. |
130
|
1 |
|
$command = Enum::LPOP; |
131
|
1 |
|
$args = [$key]; |
132
|
|
|
|
133
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @override |
138
|
|
|
* @inheritDoc |
139
|
|
|
*/ |
140
|
15 |
|
public function lPush($key,...$values) |
141
|
|
|
{ |
142
|
15 |
|
$command = Enum::LPUSH; |
143
|
15 |
|
array_unshift($values, $key); |
144
|
|
|
|
145
|
15 |
|
return $this->dispatch(Builder::build($command, $values)); |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
public function lPushX($key, $value) |
149
|
|
|
{ |
150
|
1 |
|
$command = Enum::LPUSHX; |
151
|
1 |
|
$args = [$key, $value]; |
152
|
|
|
|
153
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @override |
158
|
|
|
* @inheritDoc |
159
|
|
|
*/ |
160
|
1 |
View Code Duplication |
public function lRange($key, $start = 0, $stop = -1) |
|
|
|
|
161
|
|
|
{ |
162
|
1 |
|
$command = Enum::LRANGE; |
163
|
1 |
|
$args = [$key, $start, $stop]; |
164
|
|
|
|
165
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @override |
170
|
|
|
* @inheritDoc |
171
|
|
|
*/ |
172
|
1 |
|
public function lRem($key, $count, $value) |
173
|
|
|
{ |
174
|
|
|
// TODO: Implement lRem() method. |
175
|
1 |
|
$command = Enum::LREM; |
176
|
1 |
|
$args = [$key, $count, $value]; |
177
|
|
|
|
178
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @override |
183
|
|
|
* @inheritDoc |
184
|
|
|
*/ |
185
|
1 |
|
public function lSet($key, $index, $value) |
186
|
|
|
{ |
187
|
|
|
// TODO: Implement lSet() method. |
188
|
1 |
|
$command = Enum::LSET; |
189
|
1 |
|
$args = [$key, $index, $value]; |
190
|
|
|
|
191
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @override |
196
|
|
|
* @inheritDoc |
197
|
|
|
*/ |
198
|
1 |
|
public function lTrim($key, $start, $stop) |
199
|
|
|
{ |
200
|
|
|
// TODO: Implement lTrim() method. |
201
|
1 |
|
$command = Enum::LTRIM; |
202
|
1 |
|
$args = [$key, $start, $stop]; |
203
|
|
|
|
204
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @override |
209
|
|
|
* @inheritDoc |
210
|
|
|
*/ |
211
|
1 |
View Code Duplication |
public function rPop($key) |
|
|
|
|
212
|
|
|
{ |
213
|
1 |
|
$command = Enum::RPOP; |
214
|
1 |
|
$args = [$key]; |
215
|
|
|
|
216
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @override |
221
|
|
|
* @inheritDoc |
222
|
|
|
*/ |
223
|
1 |
View Code Duplication |
public function rPopLPush($src, $dst) |
|
|
|
|
224
|
|
|
{ |
225
|
|
|
// TODO: Implement rPopLPush() method. |
226
|
1 |
|
$command = Enum::RPOPLPUSH; |
227
|
1 |
|
$args = [$src, $dst]; |
228
|
|
|
|
229
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* @override |
234
|
|
|
* @inheritDoc |
235
|
|
|
*/ |
236
|
2 |
|
public function rPush($key, ...$values) |
237
|
|
|
{ |
238
|
2 |
|
$command = Enum::RPUSH; |
239
|
2 |
|
$args = [$key]; |
240
|
2 |
|
$args = array_merge($args, $values); |
241
|
|
|
|
242
|
2 |
|
return $this->dispatch(Builder::build($command, $args)); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @override |
247
|
|
|
* @inheritDoc |
248
|
|
|
*/ |
249
|
1 |
|
public function rPushX($key, $value) |
250
|
|
|
{ |
251
|
1 |
|
$command = Enum::RPUSHX; |
252
|
1 |
|
$args = [$key, $value]; |
253
|
|
|
|
254
|
1 |
|
return $this->dispatch(Builder::build($command, $args)); |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
|
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.