|
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 ApiSetHashTrait |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param Request $request |
|
13
|
|
|
* @return mixed |
|
14
|
|
|
*/ |
|
15
|
|
|
abstract function dispatch(Request $request); |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @override |
|
19
|
|
|
* @inheritDoc |
|
20
|
|
|
*/ |
|
21
|
|
|
public function hDel($key, ...$fields) |
|
22
|
|
|
{ |
|
23
|
|
|
$command = Enum::HDEL; |
|
24
|
|
|
$args = [$key]; |
|
25
|
|
|
$args = array_merge($args, $fields); |
|
26
|
|
|
|
|
27
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @override |
|
32
|
|
|
* @inheritDoc |
|
33
|
|
|
*/ |
|
34
|
|
|
public function hGet($key, $field) |
|
35
|
|
|
{ |
|
36
|
|
|
$command = Enum::HGET; |
|
37
|
|
|
$args = [$key, $field]; |
|
38
|
|
|
|
|
39
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @override |
|
44
|
|
|
* @inheritDoc |
|
45
|
|
|
*/ |
|
46
|
|
|
public function hGetAll($key) |
|
47
|
|
|
{ |
|
48
|
|
|
$command = Enum::HGETALL; |
|
49
|
|
|
$args = [$key]; |
|
50
|
|
|
|
|
51
|
|
|
return $this->dispatch(Builder::build($command, $args))->then(function ($value) { |
|
52
|
|
|
if (!empty($value)) { |
|
53
|
|
|
$tmp = []; |
|
54
|
|
|
$size = count($value); |
|
55
|
|
|
for ($i=0; $i<$size; $i+=2) { |
|
56
|
|
|
$field = $value[$i]; |
|
57
|
|
|
$val = $value[$i+1]; |
|
58
|
|
|
$tmp[$field] = $val; |
|
59
|
|
|
} |
|
60
|
|
|
$value = $tmp; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
return $value; |
|
64
|
|
|
}); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @override |
|
69
|
|
|
* @inheritDoc |
|
70
|
|
|
*/ |
|
71
|
|
|
public function hIncrBy($key, $field, $increment) |
|
72
|
|
|
{ |
|
73
|
|
|
$command = Enum::HINCRBY; |
|
74
|
|
|
$args = [$key, $field, $increment]; |
|
75
|
|
|
|
|
76
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @override |
|
81
|
|
|
* @inheritDoc |
|
82
|
|
|
*/ |
|
83
|
|
|
public function hIncrByFloat($key, $field, $increment) |
|
84
|
|
|
{ |
|
85
|
|
|
$command = Enum::HINCRBYFLOAT; |
|
86
|
|
|
$args = [$key, $field, $increment]; |
|
87
|
|
|
|
|
88
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @override |
|
93
|
|
|
* @inheritDoc |
|
94
|
|
|
*/ |
|
95
|
|
View Code Duplication |
public function hKeys($key) |
|
|
|
|
|
|
96
|
|
|
{ |
|
97
|
|
|
$command = Enum::HKEYS; |
|
98
|
|
|
$args = [$key]; |
|
99
|
|
|
|
|
100
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @override |
|
105
|
|
|
* @inheritDoc |
|
106
|
|
|
*/ |
|
107
|
|
View Code Duplication |
public function hLen($key) |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
$command = Enum::HLEN; |
|
110
|
|
|
$args = [$key]; |
|
111
|
|
|
|
|
112
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @override |
|
117
|
|
|
* @inheritDoc |
|
118
|
|
|
*/ |
|
119
|
|
|
public function hMGet($key, ...$fields) |
|
120
|
|
|
{ |
|
121
|
|
|
$command = Enum::HMGET; |
|
122
|
|
|
$args = [$key]; |
|
123
|
|
|
$args = array_merge($args, $fields); |
|
124
|
|
|
|
|
125
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @override |
|
130
|
|
|
* @inheritDoc |
|
131
|
|
|
*/ |
|
132
|
|
|
public function hMSet($key, array $fvMap) |
|
133
|
|
|
{ |
|
134
|
|
|
$command = Enum::HMSET; |
|
135
|
|
|
$args = [$key]; |
|
136
|
|
|
if (!empty($fvMap)) { |
|
137
|
|
|
foreach ($fvMap as $field => $value) { |
|
138
|
|
|
$tmp[] = $field; |
|
|
|
|
|
|
139
|
|
|
$tmp[] = $value; |
|
140
|
|
|
} |
|
141
|
|
|
$fvMap = $tmp; |
|
|
|
|
|
|
142
|
|
|
} |
|
143
|
|
|
$args = array_merge($args, $fvMap); |
|
144
|
|
|
|
|
145
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @override |
|
150
|
|
|
* @inheritDoc |
|
151
|
|
|
*/ |
|
152
|
|
|
public function hSet($key, $field, $value) |
|
153
|
|
|
{ |
|
154
|
|
|
$command = Enum::HSET; |
|
155
|
|
|
$args = [$key, $field, $value]; |
|
156
|
|
|
|
|
157
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @override |
|
162
|
|
|
* @inheritDoc |
|
163
|
|
|
*/ |
|
164
|
|
|
public function hSetNx($key, $filed, $value) |
|
165
|
|
|
{ |
|
166
|
|
|
$command = Enum::HSETNX; |
|
167
|
|
|
$args = [$key, $filed, $value]; |
|
168
|
|
|
|
|
169
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* @override |
|
174
|
|
|
* @inheritDoc |
|
175
|
|
|
*/ |
|
176
|
|
|
public function hStrLen($key, $field) |
|
177
|
|
|
{ |
|
178
|
|
|
$command = Enum::HSTRLEN; |
|
179
|
|
|
$args = [$key, $field]; |
|
180
|
|
|
|
|
181
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @override |
|
186
|
|
|
* @inheritDoc |
|
187
|
|
|
*/ |
|
188
|
|
View Code Duplication |
public function hVals($key) |
|
|
|
|
|
|
189
|
|
|
{ |
|
190
|
|
|
$command = Enum::HVALS; |
|
191
|
|
|
$args = [$key]; |
|
192
|
|
|
|
|
193
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @override |
|
198
|
|
|
* @inheritDoc |
|
199
|
|
|
*/ |
|
200
|
|
|
public function hScan($key, $cursor, array $options = []) |
|
201
|
|
|
{ |
|
202
|
|
|
// TODO: Implement hScan() method. |
|
203
|
|
|
$command = Enum::HSCAN; |
|
204
|
|
|
$args = [$key, $cursor]; |
|
205
|
|
|
$args = array_merge($args, $options); |
|
206
|
|
|
|
|
207
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @inheritDoc |
|
212
|
|
|
*/ |
|
213
|
|
|
public function hExists($key, $field) |
|
214
|
|
|
{ |
|
215
|
|
|
// TODO: Implement hExists() method. |
|
216
|
|
|
$command = Enum::HEXISTS; |
|
217
|
|
|
$args = [$key, $field]; |
|
218
|
|
|
|
|
219
|
|
|
return $this->dispatch(Builder::build($command, $args)); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
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.