Sitelet https://github.com/phpredis/phpredis/commit/01f3342c
Skip to content

Commit 01f3342

Browse files
committed
Issue #1894
Add XAUTOCLAIM command
1 parent 8e3c6aa commit 01f3342

6 files changed

Lines changed: 82 additions & 6 deletions

File tree

‎redis.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,10 @@ PHP_METHOD(Redis, xadd) {
36183618
REDIS_PROCESS_CMD(xadd, redis_read_variant_reply);
36193619
}
36203620

3621+
PHP_METHOD(Redis, xautoclaim) {
3622+
REDIS_PROCESS_CMD(xautoclaim, redis_xclaim_reply);
3623+
}
3624+
36213625
PHP_METHOD(Redis, xclaim) {
36223626
REDIS_PROCESS_CMD(xclaim, redis_xclaim_reply);
36233627
}

‎redis.stub.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,9 @@ public function xack(string $key, string $group, array $ids): int;
463463

464464
public function xadd(string $key, string $id, array $values, int $maxlen = 0, bool $approx = false, bool $nomkstream = false): string;
465465

466-
public function xclaim(string $key, string $group, string $consumer, int $min_iddle, array $ids, array $options): string|array;
466+
public function xautoclaim(string $key, string $group, string $consumer, int $min_idle, string $start, int $count = -1, bool $justid = false): bool|array;
467+
468+
public function xclaim(string $key, string $group, string $consumer, int $min_idle, array $ids, array $options): bool|array;
467469

468470
public function xdel(string $key, array $ids): int;
469471

‎redis_arginfo.h‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 49b5dded8c4ca8f50f0427d203e35c89278ad364 */
2+
* Stub hash: 2f9fb51ff39db0f8e399b937728904e3283448ff */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null")
@@ -751,11 +751,21 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_xadd, 0, 3, IS_STRIN
751751
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, nomkstream, _IS_BOOL, 0, "false")
752752
ZEND_END_ARG_INFO()
753753

754-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_xclaim, 0, 6, MAY_BE_STRING|MAY_BE_ARRAY)
754+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_xautoclaim, 0, 5, MAY_BE_BOOL|MAY_BE_ARRAY)
755755
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
756756
ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0)
757757
ZEND_ARG_TYPE_INFO(0, consumer, IS_STRING, 0)
758-
ZEND_ARG_TYPE_INFO(0, min_iddle, IS_LONG, 0)
758+
ZEND_ARG_TYPE_INFO(0, min_idle, IS_LONG, 0)
759+
ZEND_ARG_TYPE_INFO(0, start, IS_STRING, 0)
760+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
761+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, justid, _IS_BOOL, 0, "false")
762+
ZEND_END_ARG_INFO()
763+
764+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_xclaim, 0, 6, MAY_BE_BOOL|MAY_BE_ARRAY)
765+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
766+
ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0)
767+
ZEND_ARG_TYPE_INFO(0, consumer, IS_STRING, 0)
768+
ZEND_ARG_TYPE_INFO(0, min_idle, IS_LONG, 0)
759769
ZEND_ARG_TYPE_INFO(0, ids, IS_ARRAY, 0)
760770
ZEND_ARG_TYPE_INFO(0, options, IS_ARRAY, 0)
761771
ZEND_END_ARG_INFO()
@@ -1120,6 +1130,7 @@ ZEND_METHOD(Redis, watch);
11201130
ZEND_METHOD(Redis, wait);
11211131
ZEND_METHOD(Redis, xack);
11221132
ZEND_METHOD(Redis, xadd);
1133+
ZEND_METHOD(Redis, xautoclaim);
11231134
ZEND_METHOD(Redis, xclaim);
11241135
ZEND_METHOD(Redis, xdel);
11251136
ZEND_METHOD(Redis, xgroup);
@@ -1347,6 +1358,7 @@ static const zend_function_entry class_Redis_methods[] = {
13471358
ZEND_ME(Redis, wait, arginfo_class_Redis_wait, ZEND_ACC_PUBLIC)
13481359
ZEND_ME(Redis, xack, arginfo_class_Redis_xack, ZEND_ACC_PUBLIC)
13491360
ZEND_ME(Redis, xadd, arginfo_class_Redis_xadd, ZEND_ACC_PUBLIC)
1361+
ZEND_ME(Redis, xautoclaim, arginfo_class_Redis_xautoclaim, ZEND_ACC_PUBLIC)
13501362
ZEND_ME(Redis, xclaim, arginfo_class_Redis_xclaim, ZEND_ACC_PUBLIC)
13511363
ZEND_ME(Redis, xdel, arginfo_class_Redis_xdel, ZEND_ACC_PUBLIC)
13521364
ZEND_ME(Redis, xgroup, arginfo_class_Redis_xgroup, ZEND_ACC_PUBLIC)

‎redis_commands.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,6 +4305,49 @@ static void append_xclaim_options(smart_string *cmd, xclaimOptions *opt) {
43054305
REDIS_CMD_APPEND_SSTR_STATIC(cmd, "JUSTID");
43064306
}
43074307

4308+
4309+
int
4310+
redis_xautoclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
4311+
char **cmd, int *cmd_len, short *slot, void **ctx)
4312+
{
4313+
smart_string cmdstr = {0};
4314+
char *key, *group, *consumer, *start;
4315+
size_t keylen, grouplen, consumerlen, startlen;
4316+
zend_long min_idle, count = -1;
4317+
zend_bool justid = 0;
4318+
int argc;
4319+
4320+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sssls|lb", &key, &keylen,
4321+
&group, &grouplen, &consumer, &consumerlen,
4322+
&min_idle, &start, &startlen, &count, &justid
4323+
) == FAILURE)
4324+
{
4325+
return FAILURE;
4326+
}
4327+
4328+
argc = 5 + (count > 0 ? 1 + count : 0) + justid;
4329+
4330+
REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, argc, "XAUTOCLAIM");
4331+
redis_cmd_append_sstr_key(&cmdstr, key, keylen, redis_sock, slot);
4332+
redis_cmd_append_sstr(&cmdstr, group, grouplen);
4333+
redis_cmd_append_sstr(&cmdstr, consumer, consumerlen);
4334+
redis_cmd_append_sstr_long(&cmdstr, min_idle);
4335+
redis_cmd_append_sstr(&cmdstr, start, startlen);
4336+
4337+
if (count > 0) {
4338+
REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "COUNT");
4339+
redis_cmd_append_sstr_long(&cmdstr, count);
4340+
}
4341+
4342+
if (justid) {
4343+
REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "JUSTID");
4344+
}
4345+
4346+
*cmd = cmdstr.c;
4347+
*cmd_len = cmdstr.len;
4348+
return SUCCESS;
4349+
}
4350+
43084351
/* XCLAIM <key> <group> <consumer> <min-idle-time> <ID-1> <ID-2>
43094352
[IDLE <milliseconds>] [TIME <mstime>] [RETRYCOUNT <count>]
43104353
[FORCE] [JUSTID] */

‎redis_commands.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,9 @@ int redis_migrate_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
292292
int redis_xadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
293293
char **cmd, int *cmd_len, short *slot, void **ctx);
294294

295+
int redis_xautoclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
296+
char **cmd, int *cmd_len, short *slot, void **ctx);
297+
295298
int redis_xclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
296299
char **cmd, int *cmd_len, short *slot, void **ctx);
297300

‎redis_legacy_arginfo.h‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 49b5dded8c4ca8f50f0427d203e35c89278ad364 */
2+
* Stub hash: 2f9fb51ff39db0f8e399b937728904e3283448ff */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)
@@ -667,11 +667,21 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_xadd, 0, 0, 3)
667667
ZEND_ARG_INFO(0, nomkstream)
668668
ZEND_END_ARG_INFO()
669669

670+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_xautoclaim, 0, 0, 5)
671+
ZEND_ARG_INFO(0, key)
672+
ZEND_ARG_INFO(0, group)
673+
ZEND_ARG_INFO(0, consumer)
674+
ZEND_ARG_INFO(0, min_idle)
675+
ZEND_ARG_INFO(0, start)
676+
ZEND_ARG_INFO(0, count)
677+
ZEND_ARG_INFO(0, justid)
678+
ZEND_END_ARG_INFO()
679+
670680
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis_xclaim, 0, 0, 6)
671681
ZEND_ARG_INFO(0, key)
672682
ZEND_ARG_INFO(0, group)
673683
ZEND_ARG_INFO(0, consumer)
674-
ZEND_ARG_INFO(0, min_iddle)
684+
ZEND_ARG_INFO(0, min_idle)
675685
ZEND_ARG_INFO(0, ids)
676686
ZEND_ARG_INFO(0, options)
677687
ZEND_END_ARG_INFO()
@@ -1022,6 +1032,7 @@ ZEND_METHOD(Redis, watch);
10221032
ZEND_METHOD(Redis, wait);
10231033
ZEND_METHOD(Redis, xack);
10241034
ZEND_METHOD(Redis, xadd);
1035+
ZEND_METHOD(Redis, xautoclaim);
10251036
ZEND_METHOD(Redis, xclaim);
10261037
ZEND_METHOD(Redis, xdel);
10271038
ZEND_METHOD(Redis, xgroup);
@@ -1249,6 +1260,7 @@ static const zend_function_entry class_Redis_methods[] = {
12491260
ZEND_ME(Redis, wait, arginfo_class_Redis_wait, ZEND_ACC_PUBLIC)
12501261
ZEND_ME(Redis, xack, arginfo_class_Redis_xack, ZEND_ACC_PUBLIC)
12511262
ZEND_ME(Redis, xadd, arginfo_class_Redis_xadd, ZEND_ACC_PUBLIC)
1263+
ZEND_ME(Redis, xautoclaim, arginfo_class_Redis_xautoclaim, ZEND_ACC_PUBLIC)
12521264
ZEND_ME(Redis, xclaim, arginfo_class_Redis_xclaim, ZEND_ACC_PUBLIC)
12531265
ZEND_ME(Redis, xdel, arginfo_class_Redis_xdel, ZEND_ACC_PUBLIC)
12541266
ZEND_ME(Redis, xgroup, arginfo_class_Redis_xgroup, ZEND_ACC_PUBLIC)

0 commit comments

Comments
 (0)