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