Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2021-05-14 15:24:13 +0300
committerPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2021-05-14 15:24:13 +0300
commit568fc3a824faec7b4910b815272580ee7c93b243 (patch)
tree0a7782942bdf8c745594cd2c4bdc145564ad45d7
parenta95384f845817a4c50866656631b867406ec13eb (diff)
[WIP] Issue #1894
Add GT and LT options to ZADD.
-rw-r--r--redis_commands.c8
-rw-r--r--tests/RedisTest.php5
2 files changed, 11 insertions, 2 deletions
diff --git a/redis_commands.c b/redis_commands.c
index 16bc8e8c..22d23b82 100644
--- a/redis_commands.c
+++ b/redis_commands.c
@@ -2842,7 +2842,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char **cmd, int *cmd_len, short *slot, void **ctx)
{
zval *z_args;
- char *key, *val, *exp_type = NULL;
+ char *key, *val, *exp_type = NULL, *range_type = NULL;
size_t key_len, val_len;
int key_free, val_free;
int num = ZEND_NUM_ARGS(), i = 1, argc;
@@ -2857,7 +2857,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return FAILURE;
}
- // Need key, [NX|XX] [CH] [INCR] score, value, [score, value...] */
+ // Need key, [NX|XX] [LT|GT] [CH] [INCR] score, value, [score, value...] */
if (num % 2 == 0) {
if (Z_TYPE(z_args[1]) != IS_ARRAY) {
efree(z_args);
@@ -2868,6 +2868,8 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
if (Z_TYPE_P(z_opt) == IS_STRING) {
if (ZVAL_IS_NX_XX_ARG(z_opt)) {
exp_type = Z_STRVAL_P(z_opt);
+ } else if (ZVAL_STRICMP_STATIC(z_opt, "LT") || ZVAL_STRICMP_STATIC(z_opt, "GT")) {
+ range_type = Z_STRVAL_P(z_opt);
} else if (ZVAL_STRICMP_STATIC(z_opt, "CH")) {
ch = 1;
} else if (ZVAL_STRICMP_STATIC(z_opt, "INCR")) {
@@ -2883,6 +2885,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
} ZEND_HASH_FOREACH_END();
argc = num - 1;
if (exp_type) argc++;
+ if (range_type) argc++;
argc += ch + incr;
i++;
} else {
@@ -2905,6 +2908,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
if (key_free) efree(key);
if (exp_type) redis_cmd_append_sstr(&cmdstr, exp_type, 2);
+ if (range_type) redis_cmd_append_sstr(&cmdstr, range_type, 2);
if (ch) redis_cmd_append_sstr(&cmdstr, "CH", 2);
if (incr) redis_cmd_append_sstr(&cmdstr, "INCR", 4);
diff --git a/tests/RedisTest.php b/tests/RedisTest.php
index ed8b53f2..b6b6934c 100644
--- a/tests/RedisTest.php
+++ b/tests/RedisTest.php
@@ -2205,6 +2205,11 @@ class Redis_Test extends TestSuite
$this->assertTrue(1 === $this->redis->zAdd('key', [], 1, 'val1')); // empty options
$this->assertTrue(1 === $this->redis->zAdd('key', ['nx'], 3, 'val3')); // nx option
$this->assertTrue(0 === $this->redis->zAdd('key', ['xx'], 3, 'val3')); // xx option
+
+ if (version_compare($this->version, "6.2.0") >= 0) {
+ $this->assertTrue(0 === $this->redis->zAdd('key', ['lt'], 4, 'val3')); // lt option
+ $this->assertTrue(0 === $this->redis->zAdd('key', ['gt'], 2, 'val3')); // gt option
+ }
}
$this->assertTrue(['val0', 'val1', 'val2', 'val3', 'val4', 'val5'] === $this->redis->zRange('key', 0, -1));