Skip to content

Commit 457953f

Browse files
Refactor and fix XPENDING handler
Fixes #2128
1 parent 3b0d8b7 commit 457953f

8 files changed

+36
-29
lines changed

redis.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function xinfo(string $operation, ?string $arg1 = null, ?string $arg2 = n
507507

508508
public function xlen(string $key): int;
509509

510-
public function xpending(string $key, string $group, string $start = null, string $end = null, int $count = -1, string $consumer = null): Redis|array|false;
510+
public function xpending(string $key, string $group, ?string $start = null, ?string $end = null, int $count = -1, ?string $consumer = null): Redis|array|false;
511511

512512
public function xrange(string $key, string $start, string $end, int $count = -1): bool|array;
513513

redis_arginfo.h

Lines changed: 4 additions & 4 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: a39dd09e86258566f2eae441d920ef280f8a3e72 */
2+
* Stub hash: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */
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")
@@ -892,10 +892,10 @@ ZEND_END_ARG_INFO()
892892
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_xpending, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
893893
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
894894
ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0)
895-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 0, "null")
896-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 0, "null")
895+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 1, "null")
896+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 1, "null")
897897
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
898-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 0, "null")
898+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 1, "null")
899899
ZEND_END_ARG_INFO()
900900

901901
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_xrange, 0, 3, MAY_BE_BOOL|MAY_BE_ARRAY)

redis_cluster.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ public function xinfo(string $operation, ?string $arg1 = null, ?string $arg2 = n
348348

349349
public function xlen(string $key): int;
350350

351-
public function xpending(string $key, string $group, string $start = null, string $end = null, int $count = -1, string $consumer = null): string;
351+
public function xpending(string $key, string $group, ?string $start = null, ?string $end = null, int $count = -1, ?string $consumer = null): Redis|array|false;
352352

353353
public function xrange(string $key, string $start, string $end, int $count = -1): bool|array;
354354

redis_cluster_arginfo.h

Lines changed: 5 additions & 5 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: 396a72b8937928cf3ed504a2a8063f5090e7196b */
2+
* Stub hash: 59682d20ee8ebad4f8a5c914432f41dac0860770 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1)
@@ -749,13 +749,13 @@ ZEND_END_ARG_INFO()
749749

750750
#define arginfo_class_RedisCluster_xlen arginfo_class_RedisCluster_decr
751751

752-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_xpending, 0, 2, IS_STRING, 0)
752+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_xpending, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_FALSE)
753753
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
754754
ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0)
755-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 0, "null")
756-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 0, "null")
755+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 1, "null")
756+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 1, "null")
757757
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1")
758-
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 0, "null")
758+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 1, "null")
759759
ZEND_END_ARG_INFO()
760760

761761
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster_xrange, 0, 3, MAY_BE_BOOL|MAY_BE_ARRAY)

redis_cluster_legacy_arginfo.h

Lines changed: 1 addition & 1 deletion
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: 396a72b8937928cf3ed504a2a8063f5090e7196b */
2+
* Stub hash: 59682d20ee8ebad4f8a5c914432f41dac0860770 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1)
55
ZEND_ARG_INFO(0, name)

redis_commands.c

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5037,23 +5037,26 @@ int redis_xadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
50375037
int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
50385038
char **cmd, int *cmd_len, short *slot, void **ctx)
50395039
{
5040+
zend_string *key = NULL, *group = NULL, *start = NULL, *end = NULL,
5041+
*consumer = NULL;
5042+
zend_long count = -1, idle = 0;
50405043
smart_string cmdstr = {0};
5041-
char *key, *group, *start = NULL, *end = NULL, *consumer = NULL;
5042-
size_t keylen, grouplen, startlen, endlen, consumerlen;
50435044
int argc;
5044-
zend_long count = -1, idle = 0;
50455045

5046-
// XPENDING mystream group55 - + 10 consumer-123
5047-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|sslsl", &key,
5048-
&keylen, &group, &grouplen, &start, &startlen,
5049-
&end, &endlen, &count, &consumer, &consumerlen,
5050-
&idle) == FAILURE)
5051-
{
5052-
return FAILURE;
5053-
}
5046+
ZEND_PARSE_PARAMETERS_START(2, 7)
5047+
Z_PARAM_STR(key)
5048+
Z_PARAM_STR(group)
5049+
Z_PARAM_OPTIONAL
5050+
Z_PARAM_STR_OR_NULL(start)
5051+
Z_PARAM_STR_OR_NULL(end)
5052+
Z_PARAM_LONG(count)
5053+
Z_PARAM_STR_OR_NULL(consumer)
5054+
Z_PARAM_LONG(idle)
5055+
ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
50545056

50555057
/* If we've been passed a start argument, we also need end and count */
50565058
if (start != NULL && (end == NULL || count < 0)) {
5059+
php_error_docref(NULL, E_WARNING, "'$start' must be accompanied by '$end' and '$count' arguments");
50575060
return FAILURE;
50585061
}
50595062

@@ -5062,21 +5065,21 @@ int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
50625065

50635066
/* Construct command and add required arguments */
50645067
REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, argc, "XPENDING");
5065-
redis_cmd_append_sstr_key(&cmdstr, key, keylen, redis_sock, slot);
5066-
redis_cmd_append_sstr(&cmdstr, group, grouplen);
5068+
redis_cmd_append_sstr_key_zstr(&cmdstr, key, redis_sock, slot);
5069+
redis_cmd_append_sstr_zstr(&cmdstr, group);
50675070

50685071
/* Add optional argumentst */
50695072
if (start) {
50705073
if (idle != 0) {
50715074
REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "IDLE");
50725075
redis_cmd_append_sstr_long(&cmdstr, (long)idle);
50735076
}
5074-
redis_cmd_append_sstr(&cmdstr, start, startlen);
5075-
redis_cmd_append_sstr(&cmdstr, end, endlen);
5077+
redis_cmd_append_sstr_zstr(&cmdstr, start);
5078+
redis_cmd_append_sstr_zstr(&cmdstr, end);
50765079
redis_cmd_append_sstr_long(&cmdstr, (long)count);
50775080

50785081
/* Finally add consumer if we have it */
5079-
if (consumer) redis_cmd_append_sstr(&cmdstr, consumer, consumerlen);
5082+
if (consumer) redis_cmd_append_sstr_zstr(&cmdstr, consumer);
50805083
}
50815084

50825085
*cmd = cmdstr.c;

redis_legacy_arginfo.h

Lines changed: 1 addition & 1 deletion
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: a39dd09e86258566f2eae441d920ef280f8a3e72 */
2+
* Stub hash: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)

tests/RedisTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6604,6 +6604,10 @@ public function testXPending() {
66046604
$this->redis->xAck('s', 'group', [$id]);
66056605
}
66066606
}
6607+
6608+
/* Ensure we can have NULL trailing arguments */
6609+
$this->assertTrue(is_array($this->redis->xpending('s', 'group', '-', '+', 1, null)));
6610+
$this->assertTrue(is_array($this->redis->xpending('s', 'group', NULL, NULL, -1, NULL)));
66076611
}
66086612

66096613
public function testXDel() {

0 commit comments

Comments
 (0)