Skip to content

Commit c4cc6ca

Browse files
authored
Merge pull request ukko#40 from alexander-schranz/patch-1
Added redis stream functions
2 parents 57c7a9f + 5b62347 commit c4cc6ca

File tree

1 file changed

+214
-0
lines changed

1 file changed

+214
-0
lines changed

src/Redis.php

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

33283542
class RedisException extends Exception {}

0 commit comments

Comments
 (0)