diff options
author | michael-grunder <michael.grunder@gmail.com> | 2022-10-11 08:57:10 +0300 |
---|---|---|
committer | Michael Grunder <michael.grunder@gmail.com> | 2022-10-11 08:57:36 +0300 |
commit | 457953f4fe027a856e951c43095f2549a937cdff (patch) | |
tree | 2b5fffd1b7940eb4df13731b5d58265c7a95596f | |
parent | 3b0d8b77810a39a524b7c287d7ad646e93c20e60 (diff) |
Refactor and fix XPENDING handler
Fixes #2128
-rw-r--r-- | redis.stub.php | 2 | ||||
-rw-r--r-- | redis_arginfo.h | 8 | ||||
-rw-r--r-- | redis_cluster.stub.php | 2 | ||||
-rw-r--r-- | redis_cluster_arginfo.h | 10 | ||||
-rw-r--r-- | redis_cluster_legacy_arginfo.h | 2 | ||||
-rw-r--r-- | redis_commands.c | 35 | ||||
-rw-r--r-- | redis_legacy_arginfo.h | 2 | ||||
-rw-r--r-- | tests/RedisTest.php | 4 |
8 files changed, 36 insertions, 29 deletions
diff --git a/redis.stub.php b/redis.stub.php index 55605e96..41f9fff4 100644 --- a/redis.stub.php +++ b/redis.stub.php @@ -507,7 +507,7 @@ public function persist(string $key): bool; public function xlen(string $key): int; - public function xpending(string $key, string $group, string $start = null, string $end = null, int $count = -1, string $consumer = null): Redis|array|false; + public function xpending(string $key, string $group, ?string $start = null, ?string $end = null, int $count = -1, ?string $consumer = null): Redis|array|false; public function xrange(string $key, string $start, string $end, int $count = -1): bool|array; diff --git a/redis_arginfo.h b/redis_arginfo.h index 37265f10..61c40e72 100644 --- a/redis_arginfo.h +++ b/redis_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a39dd09e86258566f2eae441d920ef280f8a3e72 */ + * Stub hash: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "null") @@ -892,10 +892,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_xpending, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 0, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_xrange, 0, 3, MAY_BE_BOOL|MAY_BE_ARRAY) diff --git a/redis_cluster.stub.php b/redis_cluster.stub.php index b0792bd0..2a1faaf8 100644 --- a/redis_cluster.stub.php +++ b/redis_cluster.stub.php @@ -348,7 +348,7 @@ class RedisCluster { public function xlen(string $key): int; - public function xpending(string $key, string $group, string $start = null, string $end = null, int $count = -1, string $consumer = null): string; + public function xpending(string $key, string $group, ?string $start = null, ?string $end = null, int $count = -1, ?string $consumer = null): Redis|array|false; public function xrange(string $key, string $start, string $end, int $count = -1): bool|array; diff --git a/redis_cluster_arginfo.h b/redis_cluster_arginfo.h index 3c5a1e9f..1052db1e 100644 --- a/redis_cluster_arginfo.h +++ b/redis_cluster_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 396a72b8937928cf3ed504a2a8063f5090e7196b */ + * Stub hash: 59682d20ee8ebad4f8a5c914432f41dac0860770 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 1) @@ -749,13 +749,13 @@ ZEND_END_ARG_INFO() #define arginfo_class_RedisCluster_xlen arginfo_class_RedisCluster_decr -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_RedisCluster_xpending, 0, 2, IS_STRING, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_RedisCluster_xpending, 0, 2, Redis, MAY_BE_ARRAY|MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, group, IS_STRING, 0) - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 0, "null") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_STRING, 1, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, end, IS_STRING, 1, "null") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "-1") - ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 0, "null") + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, consumer, IS_STRING, 1, "null") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_RedisCluster_xrange, 0, 3, MAY_BE_BOOL|MAY_BE_ARRAY) diff --git a/redis_cluster_legacy_arginfo.h b/redis_cluster_legacy_arginfo.h index dd9e3196..3484a2db 100644 --- a/redis_cluster_legacy_arginfo.h +++ b/redis_cluster_legacy_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 396a72b8937928cf3ed504a2a8063f5090e7196b */ + * Stub hash: 59682d20ee8ebad4f8a5c914432f41dac0860770 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RedisCluster___construct, 0, 0, 1) ZEND_ARG_INFO(0, name) diff --git a/redis_commands.c b/redis_commands.c index 9a2395dc..f74b2799 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -5037,23 +5037,26 @@ int redis_xadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char **cmd, int *cmd_len, short *slot, void **ctx) { + zend_string *key = NULL, *group = NULL, *start = NULL, *end = NULL, + *consumer = NULL; + zend_long count = -1, idle = 0; smart_string cmdstr = {0}; - char *key, *group, *start = NULL, *end = NULL, *consumer = NULL; - size_t keylen, grouplen, startlen, endlen, consumerlen; int argc; - zend_long count = -1, idle = 0; - // XPENDING mystream group55 - + 10 consumer-123 - if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|sslsl", &key, - &keylen, &group, &grouplen, &start, &startlen, - &end, &endlen, &count, &consumer, &consumerlen, - &idle) == FAILURE) - { - return FAILURE; - } + ZEND_PARSE_PARAMETERS_START(2, 7) + Z_PARAM_STR(key) + Z_PARAM_STR(group) + Z_PARAM_OPTIONAL + Z_PARAM_STR_OR_NULL(start) + Z_PARAM_STR_OR_NULL(end) + Z_PARAM_LONG(count) + Z_PARAM_STR_OR_NULL(consumer) + Z_PARAM_LONG(idle) + ZEND_PARSE_PARAMETERS_END_EX(return FAILURE); /* If we've been passed a start argument, we also need end and count */ if (start != NULL && (end == NULL || count < 0)) { + php_error_docref(NULL, E_WARNING, "'$start' must be accompanied by '$end' and '$count' arguments"); return FAILURE; } @@ -5062,8 +5065,8 @@ int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, /* Construct command and add required arguments */ REDIS_CMD_INIT_SSTR_STATIC(&cmdstr, argc, "XPENDING"); - redis_cmd_append_sstr_key(&cmdstr, key, keylen, redis_sock, slot); - redis_cmd_append_sstr(&cmdstr, group, grouplen); + redis_cmd_append_sstr_key_zstr(&cmdstr, key, redis_sock, slot); + redis_cmd_append_sstr_zstr(&cmdstr, group); /* Add optional argumentst */ if (start) { @@ -5071,12 +5074,12 @@ int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, REDIS_CMD_APPEND_SSTR_STATIC(&cmdstr, "IDLE"); redis_cmd_append_sstr_long(&cmdstr, (long)idle); } - redis_cmd_append_sstr(&cmdstr, start, startlen); - redis_cmd_append_sstr(&cmdstr, end, endlen); + redis_cmd_append_sstr_zstr(&cmdstr, start); + redis_cmd_append_sstr_zstr(&cmdstr, end); redis_cmd_append_sstr_long(&cmdstr, (long)count); /* Finally add consumer if we have it */ - if (consumer) redis_cmd_append_sstr(&cmdstr, consumer, consumerlen); + if (consumer) redis_cmd_append_sstr_zstr(&cmdstr, consumer); } *cmd = cmdstr.c; diff --git a/redis_legacy_arginfo.h b/redis_legacy_arginfo.h index b3b61151..d2a8c22c 100644 --- a/redis_legacy_arginfo.h +++ b/redis_legacy_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: a39dd09e86258566f2eae441d920ef280f8a3e72 */ + * Stub hash: 73e34ca5d2f49dd1dbcbf901d3dd48019e1ba5dc */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0) ZEND_ARG_INFO(0, options) diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 044c7884..c55f65a8 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -6604,6 +6604,10 @@ class Redis_Test extends TestSuite $this->redis->xAck('s', 'group', [$id]); } } + + /* Ensure we can have NULL trailing arguments */ + $this->assertTrue(is_array($this->redis->xpending('s', 'group', '-', '+', 1, null))); + $this->assertTrue(is_array($this->redis->xpending('s', 'group', NULL, NULL, -1, NULL))); } public function testXDel() { |