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@users.noreply.github.com>2020-05-19 04:11:40 +0300
committerGitHub <noreply@github.com>2020-05-19 04:11:40 +0300
commite80600e244b8442cb7c86e99b067966cd59bf2ee (patch)
treeeb6f7a91da7ad74602e1812267514c66287d460b /redis_cluster.c
parent508fef6f18c8ee7e57ff6fc45697248c0bd72709 (diff)
Issue #548 (#1649)
Adds `Redis::SCAN_PREFIX` and `Redis::SCAN_NOPREFIX` as options to SCAN. See #548
Diffstat (limited to 'redis_cluster.c')
-rw-r--r--redis_cluster.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/redis_cluster.c b/redis_cluster.c
index 7f79b5fe..0fc94fe3 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -2411,7 +2411,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
{
redisCluster *c = GET_CONTEXT();
char *cmd, *pat = NULL, *key = NULL;
- size_t key_len = 0, pat_len = 0;
+ size_t key_len = 0, pat_len = 0, pat_free = 0;
int cmd_len, key_free = 0;
short slot;
zval *z_it;
@@ -2450,6 +2450,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
key_free = redis_key_prefix(c->flags, &key, &key_len);
slot = cluster_hash_key(key, key_len);
+ if (c->flags->scan & REDIS_SCAN_PREFIX) {
+ pat_free = redis_key_prefix(c->flags, &pat, &pat_len);
+ }
+
// If SCAN_RETRY is set, loop until we get a zero iterator or until
// we get non-zero elements. Otherwise we just send the command once.
do {
@@ -2488,7 +2492,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
// Free our command
efree(cmd);
- } while (c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+ } while (c->flags->scan & REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+
+ // Free our pattern
+ if (pat_free) efree(pat);
// Free our key
if (key_free) efree(key);
@@ -2505,7 +2512,7 @@ PHP_METHOD(RedisCluster, scan) {
int cmd_len;
short slot;
zval *z_it, *z_node;
- long it, num_ele;
+ long it, num_ele, pat_free = 0;
zend_long count = 0;
/* Treat as read-only */
@@ -2534,6 +2541,10 @@ PHP_METHOD(RedisCluster, scan) {
RETURN_FALSE;
}
+ if (c->flags->scan & REDIS_SCAN_PREFIX) {
+ pat_free = redis_key_prefix(c->flags, &pat, &pat_len);
+ }
+
/* With SCAN_RETRY on, loop until we get some keys, otherwise just return
* what Redis does, as it does */
do {
@@ -2570,7 +2581,9 @@ PHP_METHOD(RedisCluster, scan) {
efree(cmd);
num_ele = zend_hash_num_elements(Z_ARRVAL_P(return_value));
- } while (c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+ } while (c->flags->scan & REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+
+ if (pat_free) efree(pat);
Z_LVAL_P(z_it) = it;
}