Skip to content

Commit 8cae848

Browse files
added redis stream functions
1 parent 57c7a9f commit 8cae848

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

src/Redis.php

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,206 @@ public function rawCommand( $command, $arguments ) {}
33233323
* @example $redis->getMode();
33243324
*/
33253325
public function getMode() {}
3326+
3327+
/**
3328+
* Acknowledge one or more messages on behalf of a consumer group.
3329+
* @param string $stream
3330+
* @param string $group
3331+
* @param array $arr_messages
3332+
* @return int The number of messages Redis reports as acknowledged.
3333+
* @example
3334+
* <pre>
3335+
* $obj_redis->xAck('stream', 'group1', ['1530063064286-0', '1530063064286-1']);
3336+
* </pre>
3337+
*/
3338+
public function xAck($stream, $group, $arr_messages) {}
3339+
3340+
/**
3341+
* Add a message to a stream.
3342+
* @param string $str_key
3343+
* @param string $str_id
3344+
* @param $arr_message
3345+
* @return string The added message ID.
3346+
* @example
3347+
* <pre>
3348+
* $obj_redis->xAdd('mystream', "\*", ['field' => 'value']);
3349+
* </pre>
3350+
*/
3351+
public function xAdd($str_key, $str_id, $arr_message) {}
3352+
3353+
/**
3354+
* Claim ownership of one or more pending messages.
3355+
* @param string $str_key
3356+
* @param string $str_group
3357+
* @param string $str_consumer
3358+
* @param array $ids
3359+
* @param array $arr_options ['IDLE' => $value, 'TIME' => $value, 'RETRYCOUNT' => $value, 'FORCE', 'JUSTID']
3360+
* @return array Either an array of message IDs along with corresponding data, or just an array of IDs (if the 'JUSTID' option was passed).
3361+
* @example
3362+
* <pre>
3363+
* $ids = ['1530113681011-0', '1530113681011-1', '1530113681011-2'];
3364+
*
3365+
* // Without any options
3366+
* $obj_redis->xClaim('mystream', 'group1', 'myconsumer1', $ids);
3367+
*
3368+
* // With options
3369+
* $obj_redis->xClaim(
3370+
* 'mystream', 'group1', 'myconsumer2', $ids,
3371+
* [
3372+
* 'IDLE' => time() * 1000,
3373+
* 'RETRYCOUNT' => 5,
3374+
* 'FORCE',
3375+
* 'JUSTID'
3376+
* ]
3377+
* );
3378+
* </pre>
3379+
*/
3380+
public function xClaim($str_key, $str_group, $str_consumer, $ids, $arr_options = []) {}
3381+
3382+
/**
3383+
* Delete one or more messages from a stream.
3384+
* @param string $str_key
3385+
* @param array $arr_ids
3386+
* @return int The number of messages removed.
3387+
* @example
3388+
* <pre>
3389+
* $obj_redis->xDel('mystream', ['1530115304877-0', '1530115305731-0']);
3390+
* </pre>
3391+
*/
3392+
public function xDel($str_key, $arr_ids) {}
3393+
3394+
/**
3395+
* @param string $operation e.g.: 'HELP', 'SETID', 'DELGROUP', 'CREATE', 'DELCONSUMER'
3396+
* @param string $str_key
3397+
* @param string $str_group
3398+
* @param string $str_msg_id
3399+
* @return mixed This command returns different types depending on the specific XGROUP command executed.
3400+
* @example
3401+
* <pre>
3402+
* $obj_redis->xGroup('CREATE', 'mystream', 'mygroup');
3403+
* $obj_redis->xGroup('DELGROUP', 'mystream', 'mygroup');
3404+
* </pre>
3405+
*/
3406+
public function xGroup($operation, $str_key, $str_group, $str_msg_id) {}
3407+
3408+
/**
3409+
* Get information about a stream or consumer groups.
3410+
* @param string $operation e.g.: 'CONSUMERS', 'GROUPS', 'STREAM', 'HELP'
3411+
* @param string $str_stream
3412+
* @param string $str_group
3413+
* @return mixed This command returns different types depending on which subcommand is used.
3414+
* @example
3415+
* <pre>
3416+
* $obj_redis->xInfo('STREAM', 'mystream');
3417+
* </pre>
3418+
*/
3419+
public function xInfo($operation, $str_stream, $str_group) {}
3420+
3421+
/**
3422+
* Get the length of a given stream.
3423+
* @param string $str_stream
3424+
* @return int The number of messages in the stream.
3425+
* @example
3426+
* <pre>
3427+
* $obj_redis->xLen('mystream');
3428+
* </pre>
3429+
*/
3430+
public function xLen($str_stream) {}
3431+
3432+
/**
3433+
* Get information about pending messages in a given stream.
3434+
* @param string $str_stream
3435+
* @param string $str_group
3436+
* @param int|string $i_start
3437+
* @param int|string $i_end
3438+
* @param int|string $i_count
3439+
* @param string $str_consumer
3440+
* @return array Information about the pending messages, in various forms depending on the specific invocation of XPENDING.
3441+
* @example
3442+
* <pre>
3443+
* $obj_redis->xPending('mystream', 'mygroup');
3444+
* $obj_redis->xPending('mystream', 'mygroup', 0, '+', 1, 'consumer-1');
3445+
* </pre>
3446+
*/
3447+
public function xPending($str_stream, $str_group, $i_start = null, $i_end = null, $i_count = null, $str_consumer = null) {}
3448+
3449+
/**
3450+
* Get a range of messages from a given stream.
3451+
* @param string $str_stream
3452+
* @param int $i_start
3453+
* @param int $i_end
3454+
* @param int $i_count
3455+
* @return array The messages in the stream within the requested range.
3456+
* @example
3457+
* <pre>
3458+
* // Get everything in this stream
3459+
* $obj_redis->xRange('mystream', '-', '+');
3460+
* // Only the first two messages
3461+
* $obj_redis->xRange('mystream', '-', '+', 2);
3462+
* </pre>
3463+
*/
3464+
public function xRange($str_stream, $i_start, $i_end, $i_count = null) {}
3465+
3466+
/**
3467+
* Read data from one or more streams and only return IDs greater than sent in the command.
3468+
* @param $arr_streams
3469+
* @param int|string $i_count
3470+
* @param int|string $i_block
3471+
* @return array The messages in the stream newer than the IDs passed to Redis (if any).
3472+
* @example
3473+
* <pre>
3474+
* $obj_redis->xRead(['stream1' => '1535222584555-0', 'stream2' => '1535222584555-0']);
3475+
* </pre>
3476+
*/
3477+
public function xRead($arr_streams, $i_count = null, $i_block = null) {}
3478+
3479+
/**
3480+
* This method is similar to xRead except that it supports reading messages for a specific consumer group.
3481+
* @param string $str_group
3482+
* @param string $str_consumer
3483+
* @param array $arr_streams
3484+
* @param int|string $i_count
3485+
* @param int|string $i_block
3486+
* @return array The messages delivered to this consumer group (if any).
3487+
* @example
3488+
* <pre>
3489+
* // Consume messages for 'mygroup', 'consumer1'
3490+
* $obj_redis->xReadGroup('mygroup', 'consumer1', ['s1' => 0, 's2' => 0]);
3491+
* // Read a single message as 'consumer2' for up to a second until a message arrives.
3492+
* $obj_redis->xReadGroup('mygroup', 'consumer2', ['s1' => 0, 's2' => 0], 1, 1000);
3493+
* </pre>
3494+
*/
3495+
public function xReadGroup($str_group, $str_consumer, $arr_streams, $i_count, $i_block = null) {}
3496+
3497+
/**
3498+
* This is identical to xRange except the results come back in reverse order. Also note that Redis reverses the order of "start" and "end".
3499+
* @param string $str_stream
3500+
* @param int|string $i_end
3501+
* @param int|string $i_start
3502+
* @param int|string $i_count
3503+
* @return array The messages in the range specified.
3504+
* @example
3505+
* <pre>
3506+
* $obj_redis->xRevRange('mystream', '+', '-');
3507+
* </pre>
3508+
*/
3509+
public function xRevRange($str_stream, $i_end, $i_start, $i_count = null) {}
3510+
3511+
/**
3512+
* Trim the stream length to a given maximum. If the "approximate" flag is pasesed, Redis will use your size as a hint but only trim trees in whole nodes (this is more efficient)..
3513+
* @param string $str_stream
3514+
* @param int $i_max_len
3515+
* @param bool $boo_approximate
3516+
* @return int The number of messages trimed from the stream.
3517+
* @example
3518+
* <pre>
3519+
* // Trim to exactly 100 messages
3520+
* $obj_redis->xTrim('mystream', 100);
3521+
* // Let Redis approximate the trimming
3522+
* $obj_redis->xTrim('mystream', 100, true);
3523+
* </pre>
3524+
*/
3525+
public function xTrim($str_stream, $i_max_len, $boo_approximate) {}
33263526
}
33273527

33283528
class RedisException extends Exception {}

0 commit comments

Comments
 (0)