diff options
author | michael-grunder <michael.grunder@gmail.com> | 2014-07-11 20:47:30 +0400 |
---|---|---|
committer | michael-grunder <michael.grunder@gmail.com> | 2015-05-06 01:04:12 +0300 |
commit | 265837230d5fa52a07d1bfcbfa40affc521460ef (patch) | |
tree | 2c83c416896e1f908e5f5025fe50109f8c3dbf32 | |
parent | 77bcc2b2c436318d3e43ba6c86e51cbd4a32cffe (diff) |
ZREMRANGEBYLEX
Implemented ZREMRANGEBYLEX in Redis and RedisCluster, and made the
zlexcount command generic, as it has the same semantics.
-rw-r--r-- | php_redis.h | 1 | ||||
-rw-r--r-- | redis.c | 10 | ||||
-rw-r--r-- | redis_cluster.c | 12 | ||||
-rw-r--r-- | redis_cluster.h | 1 | ||||
-rw-r--r-- | redis_commands.c | 79 | ||||
-rw-r--r-- | redis_commands.h | 6 |
6 files changed, 64 insertions, 45 deletions
diff --git a/php_redis.h b/php_redis.h index 804740d6..6077c8b1 100644 --- a/php_redis.h +++ b/php_redis.h @@ -117,6 +117,7 @@ PHP_METHOD(Redis, zRangeByLex); PHP_METHOD(Redis, zRevRangeByScore); PHP_METHOD(Redis, zRangeByLex); PHP_METHOD(Redis, zRevRangeByLex); +PHP_METHOD(Redis, zRemRangeByLex); PHP_METHOD(Redis, zLexCount); PHP_METHOD(Redis, zCount); PHP_METHOD(Redis, zDeleteRangeByScore); @@ -199,6 +199,7 @@ static zend_function_entry redis_functions[] = { PHP_ME(Redis, zRangeByLex, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, zRevRangeByLex, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, zLexCount, NULL, ZEND_ACC_PUBLIC) + PHP_ME(Redis, zRemRangeByLex, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, zCount, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, zDeleteRangeByScore, NULL, ZEND_ACC_PUBLIC) PHP_ME(Redis, zDeleteRangeByRank, NULL, ZEND_ACC_PUBLIC) @@ -2021,7 +2022,14 @@ PHP_METHOD(Redis, zRevRangeByLex) { /* {{{ proto long Redis::zLexCount(string key, string min, string max) */ PHP_METHOD(Redis, zLexCount) { - REDIS_PROCESS_CMD(zlexcount, redis_long_response); + REDIS_PROCESS_KW_CMD("ZLEXCOUNT", redis_gen_zlex_cmd, redis_long_response); +} +/* }}} */ + +/* {{{ proto long Redis::zRemRangeByLex(string key, string min, string max) */ +PHP_METHOD(Redis, zRemRangeByLex) { + REDIS_PROCESS_KW_CMD("ZREMRANGEBYLEX", redis_gen_zlex_cmd, + redis_long_response); } /* }}} */ diff --git a/redis_cluster.c b/redis_cluster.c index a0b37e95..cdf5f339 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -159,6 +159,7 @@ zend_function_entry redis_cluster_functions[] = { PHP_ME(RedisCluster, zrangebylex, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zrevrangebylex, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zlexcount, NULL, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, zremrangebylex, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zunionstore, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zinterstore, NULL, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zrem, NULL, ZEND_ACC_PUBLIC) @@ -1441,9 +1442,16 @@ PHP_METHOD(RedisCluster, zrevrangebylex) { } /* }}} */ -/* {{{ proto RedisCluster::zlexcount(string key, string min, string max) */ +/* {{{ proto long RedisCluster::zlexcount(string key, string min, string max) */ PHP_METHOD(RedisCluster, zlexcount) { - CLUSTER_PROCESS_CMD(zlexcount, cluster_long_resp); + CLUSTER_PROCESS_KW_CMD("ZLEXCOUNT", redis_gen_zlex_cmd, cluster_long_resp); +} +/* }}} */ + +/* {{{ proto long RedisCluster::zremrangebylex(string key, string min, string max) */ +PHP_METHOD(RedisCluster, zremrangebylex) { + CLUSTER_PROCESS_KW_CMD("ZREMRANGEBYLEX", redis_gen_zlex_cmd, + cluster_long_resp); } /* }}} */ diff --git a/redis_cluster.h b/redis_cluster.h index 3d7363c5..66d88d63 100644 --- a/redis_cluster.h +++ b/redis_cluster.h @@ -217,6 +217,7 @@ PHP_METHOD(RedisCluster, zrevrangebyscore); PHP_METHOD(RedisCluster, zrangebylex); PHP_METHOD(RedisCluster, zrevrangebylex); PHP_METHOD(RedisCluster, zlexcount); +PHP_METHOD(RedisCluster, zremrangebylex); PHP_METHOD(RedisCluster, zunionstore); PHP_METHOD(RedisCluster, zinterstore); PHP_METHOD(RedisCluster, sort); diff --git a/redis_commands.c b/redis_commands.c index c34409af..39ed31b0 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -856,6 +856,46 @@ int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, return SUCCESS; } +/* ZLEXCOUNT/ZREMRANGEBYLEX */ +int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, + void **ctx) +{ + char *key, *min, *max; + int key_len, min_len, max_len, key_free; + + /* Parse args */ + if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &key, &key_len, + &min, &min_len, &max, &max_len)==FAILURE) + { + return FAILURE; + } + + /* Quick sanity check on min/max */ + if(min_len<1 || max_len<1 || (min[0]!='(' && min[0]!='[') || + (max[0]!='(' && max[0]!='[')) + { + php_error_docref(NULL TSRMLS_CC, E_WARNING, + "Min and Max arguments must begin with '(' or '['"); + return FAILURE; + } + + /* Prefix key if we need to */ + key_free = redis_key_prefix(redis_sock, &key, &key_len); + + /* Construct command */ + *cmd_len = redis_cmd_format_static(cmd, kw, "sss", key, key_len, min, + min_len, max, max_len); + + /* set slot */ + CMD_SET_SLOT(slot,key,key_len); + + /* Free key if prefixed */ + if(key_free) efree(key); + + return SUCCESS; +} + /* Commands that take a key followed by a variable list of serializable * values (RPUSH, LPUSH, SADD, SREM, etc...) */ int redis_key_varval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, @@ -2452,45 +2492,6 @@ int redis_sdiffstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, "SDIFFSTORE", sizeof("SDIFFSTORE")-1, 2, 0, cmd, cmd_len, slot); } -/* ZLEXCOUNT */ -int redis_zlexcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx) -{ - char *key, *min, *max; - int key_len, min_len, max_len, key_free; - - /* Parse args */ - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &key, &key_len, - &min, &min_len, &max, &max_len)==FAILURE) - { - return FAILURE; - } - - /* Quick sanity check on min/max */ - if(min_len<1 || max_len<1 || (min[0]!='(' && min[0]!='[') || - (max[0]!='(' && max[0]!='[')) - { - php_error_docref(NULL TSRMLS_CC, E_WARNING, - "Min and Max arguments must begin with '(' or '['"); - return FAILURE; - } - - /* Prefix key if we need to */ - key_free = redis_key_prefix(redis_sock, &key, &key_len); - - /* Construct command */ - *cmd_len = redis_cmd_format_static(cmd, "ZLEXCOUNT", "sss", key, key_len, - min, min_len, max, max_len); - - /* set slot */ - CMD_SET_SLOT(slot,key,key_len); - - /* Free key if prefixed */ - if(key_free) efree(key); - - return SUCCESS; -} - /* * Redis commands that don't deal with the server at all. The RedisSock* * pointer is the only thing retreived differently, so we just take that diff --git a/redis_commands.h b/redis_commands.h index af39eac3..f8f1e879 100644 --- a/redis_commands.h +++ b/redis_commands.h @@ -92,6 +92,9 @@ int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); +int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, + char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); + /* Commands which need a unique construction mechanism. This is either because * they don't share a signature with any other command, or because there is * specific processing we do (e.g. verifying subarguments) that make them @@ -200,9 +203,6 @@ int redis_sdiff_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int redis_sdiffstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char **cmd, int *cmd_len, short *slot, void **ctx); -int redis_zlexcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, - char **cmd, int *cmd_len, short *slot, void **ctx); - int redis_fmt_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len, long it, char *pat, int pat_len, long count); |