1 | <?php |
||
5 | trait Streams |
||
6 | { |
||
7 | /** |
||
8 | * Acknowledge one or more pending messages. |
||
9 | * |
||
10 | * See: https://redis.io/commands/xack. |
||
11 | * |
||
12 | * @param string $stream |
||
13 | * @param string $group |
||
14 | * @param array $messages |
||
15 | * |
||
16 | * @return int The number of messages Redis reports as acknowledged. |
||
17 | */ |
||
18 | public function xAck(string $stream, string $group, array $messages): int |
||
22 | |||
23 | |||
24 | /** |
||
25 | * Appends the specified stream entry to the stream at the specified key. |
||
26 | * If the key does not exist, as a side effect of running this command the |
||
27 | * key is created with a stream value. |
||
28 | * |
||
29 | * See: https://redis.io/commands/xadd. |
||
30 | * |
||
31 | * @param string $key |
||
32 | * @param string $id |
||
33 | * @param array $message |
||
34 | * @param int|integer $maxLenght |
||
35 | * @param bool $approximate |
||
36 | * |
||
37 | * @return string The added message ID |
||
38 | */ |
||
39 | public function xAdd( |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Claim ownership of one or more pending messages. |
||
58 | * |
||
59 | * See: https://redis.io/commands/xclaim. |
||
60 | * |
||
61 | * @param string $stream |
||
62 | * @param string $group |
||
63 | * @param string $consumer |
||
64 | * @param int $minIdleTime |
||
65 | * @param array $messageIds |
||
66 | * @param array|null $options |
||
67 | * |
||
68 | * @return array Either an array of message IDs along with |
||
69 | * corresponding data, or just an array of |
||
70 | * IDs (if the 'JUSTID' option was passed). |
||
71 | */ |
||
72 | public function xClaim( |
||
88 | |||
89 | |||
90 | /** |
||
91 | * Delete one or more messages from a stream. |
||
92 | * |
||
93 | * See: https://redis.io/commands/xdel. |
||
94 | * |
||
95 | * @param string $stream |
||
96 | * @param array $messageIds |
||
97 | * |
||
98 | * @return int The number of messages removed. |
||
99 | */ |
||
100 | public function xDel(string $stream, array $messageIds): int |
||
104 | |||
105 | |||
106 | /** |
||
107 | * This command is used in order to create, destroy, or manage consumer groups. |
||
108 | * |
||
109 | * See: https://redis.io/commands/xgroup. |
||
110 | * |
||
111 | * @param string $command [description] |
||
112 | * @param string|null $stream [description] |
||
113 | * @param string|null $group [description] |
||
114 | * @param [type] $messageId_consumerName [description] |
||
115 | * @param bool|boolean $makeStream [description] |
||
116 | * |
||
117 | * @return mixed This command returns different |
||
118 | * types depending on the specific |
||
119 | * XGROUP command executed. |
||
120 | */ |
||
121 | public function xGroup( |
||
130 | |||
131 | |||
132 | /** |
||
133 | * Get information about a stream or consumer groups. |
||
134 | * |
||
135 | * See: https://redis.io/commands/xinfo. |
||
136 | * |
||
137 | * @param string $command |
||
138 | * @param string $stream |
||
139 | * @param string $group |
||
140 | * |
||
141 | * @return mixed This command returns different types depending on which subcommand is used. |
||
142 | */ |
||
143 | public function xInfo(string $command, ?string $stream = null, ?string $group = null) |
||
159 | |||
160 | |||
161 | /** |
||
162 | * Get the length of a given stream. |
||
163 | * |
||
164 | * See: https://redis.io/commands/xlen. |
||
165 | * |
||
166 | * @param string $stream |
||
167 | * |
||
168 | * @return The number of messages in the stream. |
||
169 | */ |
||
170 | public function xLen(string $stream): int |
||
174 | |||
175 | |||
176 | /** |
||
177 | * Get information about pending messages in a given stream. |
||
178 | * |
||
179 | * See: https://redis.io/commands/xpending. |
||
180 | * |
||
181 | * @param string $stream |
||
182 | * @param string $group |
||
183 | * @param string|null $start |
||
184 | * @param string|null $end |
||
185 | * @param int|null $count |
||
186 | * @param string|null $consumer |
||
187 | * |
||
188 | * @return array Information about the pending messages, |
||
189 | * in various forms depending on the specific |
||
190 | * invocation of XPENDING. |
||
191 | */ |
||
192 | public function xPending( |
||
204 | |||
205 | |||
206 | /** |
||
207 | * Get a range of messages from a given stream. |
||
208 | * |
||
209 | * See: https://redis.io/commands/xrange. |
||
210 | * |
||
211 | * @param string $stream |
||
212 | * @param string $start |
||
213 | * @param string $end |
||
214 | * @param int|null $count |
||
215 | * |
||
216 | * @return array The messages in the stream within the requested range. |
||
217 | */ |
||
218 | public function xRange(string $stream, string $start, string $end, ?int $count = null): array |
||
224 | |||
225 | |||
226 | /** |
||
227 | * Read data from one or more streams and only return IDs greater than sent in the command. |
||
228 | * |
||
229 | * See: https://redis.io/commands/xread. |
||
230 | * |
||
231 | * @param array $streams |
||
232 | * @param int|null $count |
||
233 | * @param int|null $block |
||
234 | * |
||
235 | * @return array The messages in the stream newer than the IDs passed to Redis (if any). |
||
236 | */ |
||
237 | public function xRead(array $streams, ?int $count = null, ?int $block = null): array |
||
245 | |||
246 | |||
247 | public function xReadGroup(): array |
||
251 | |||
252 | public function xRevRange(): bool |
||
256 | |||
257 | public function xTrim(): bool |
||
261 | |||
262 | |||
263 | /** |
||
264 | * ************************************************************************ |
||
265 | * H E L P E R F U N C T I O N S |
||
266 | * ************************************************************************ |
||
267 | */ |
||
268 | |||
269 | |||
270 | /** |
||
271 | * Claim Options available |
||
272 | * |
||
273 | * Note: 'TIME', and 'IDLE' are mutually exclusive |
||
274 | * |
||
275 | * 'IDLE' => $value, Set the idle time to $value ms |
||
276 | * 'TIME' => $value, Set the idle time to now - $value |
||
277 | * 'RETRYCOUNT' => $value, Update message retrycount to $value |
||
278 | * 'FORCE', Claim the message(s) even if they're not pending anywhere |
||
279 | * 'JUSTID',Instruct Redis to only return IDs |
||
280 | * |
||
281 | * @param array $options |
||
282 | * |
||
283 | * @return bool |
||
284 | */ |
||
285 | private function _checkClaimOptions(array $options): bool |
||
298 | |||
299 | |||
300 | /** |
||
301 | * [_checkInfoCommands description] |
||
302 | * |
||
303 | * @param string $command |
||
304 | * |
||
305 | * @return bool |
||
306 | */ |
||
307 | private function _checkInfoCommands(string $command): bool |
||
313 | } |
||
314 |
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: