diff options
author | Marin Bezhanov <marin.bezhanov@gmail.com> | 2019-02-17 14:05:58 +0300 |
---|---|---|
committer | Marin Bezhanov <marin.bezhanov@gmail.com> | 2019-02-17 14:05:58 +0300 |
commit | 46f035615ecaf839cfe515dac39f209d50689461 (patch) | |
tree | 977e69e8f4e3e8043757c4204f9a1addf2d2c89a | |
parent | 22d81a94eee2ea613fc515e1d714b73142d46241 (diff) |
Add ZPOPMAX and ZPOPMIN support
-rw-r--r-- | php_redis.h | 2 | ||||
-rw-r--r-- | redis.c | 28 | ||||
-rw-r--r-- | redis_cluster.c | 26 | ||||
-rw-r--r-- | redis_cluster.h | 2 | ||||
-rw-r--r-- | tests/RedisTest.php | 23 |
5 files changed, 81 insertions, 0 deletions
diff --git a/php_redis.h b/php_redis.h index 8dc2f5c6..1f1eb1ac 100644 --- a/php_redis.h +++ b/php_redis.h @@ -131,6 +131,8 @@ PHP_METHOD(Redis, zRevRank); PHP_METHOD(Redis, zIncrBy); PHP_METHOD(Redis, zInter); PHP_METHOD(Redis, zUnion); +PHP_METHOD(Redis, zPopMax); +PHP_METHOD(Redis, zPopMin); PHP_METHOD(Redis, expireAt); PHP_METHOD(Redis, pexpireAt); PHP_METHOD(Redis, bgrewriteaof); @@ -445,6 +445,8 @@ static zend_function_entry redis_functions[] = { PHP_ME(Redis, zScore, arginfo_key_member, ZEND_ACC_PUBLIC) PHP_ME(Redis, zUnion, arginfo_zstore, ZEND_ACC_PUBLIC) PHP_ME(Redis, zscan, arginfo_kscan, ZEND_ACC_PUBLIC) + PHP_ME(Redis, zPopMax, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(Redis, zPopMin, arginfo_key, ZEND_ACC_PUBLIC) PHP_MALIAS(Redis, del, delete, arginfo_del, ZEND_ACC_PUBLIC) PHP_MALIAS(Redis, evaluate, eval, arginfo_eval, ZEND_ACC_PUBLIC) PHP_MALIAS(Redis, evaluateSha, evalsha, arginfo_evalsha, ZEND_ACC_PUBLIC) @@ -2138,6 +2140,32 @@ PHP_METHOD(Redis, zUnion) { REDIS_PROCESS_KW_CMD("ZUNIONSTORE", redis_zinter_cmd, redis_long_response); } +/* {{{ proto array Redis::zPopMax(string key) */ +PHP_METHOD(Redis, zPopMax) +{ + if (ZEND_NUM_ARGS() == 1) { + REDIS_PROCESS_KW_CMD("ZPOPMAX", redis_key_cmd, redis_sock_read_multibulk_reply); + } else if (ZEND_NUM_ARGS() == 2) { + REDIS_PROCESS_KW_CMD("ZPOPMAX", redis_key_long_cmd, redis_sock_read_multibulk_reply); + } else { + ZEND_WRONG_PARAM_COUNT(); + } +} +/* }}} */ + +/* {{{ proto array Redis::zPopMin(string key) */ +PHP_METHOD(Redis, zPopMin) +{ + if (ZEND_NUM_ARGS() == 1) { + REDIS_PROCESS_KW_CMD("ZPOPMIN", redis_key_cmd, redis_sock_read_multibulk_reply); + } else if (ZEND_NUM_ARGS() == 2) { + REDIS_PROCESS_KW_CMD("ZPOPMIN", redis_key_long_cmd, redis_sock_read_multibulk_reply); + } else { + ZEND_WRONG_PARAM_COUNT(); + } +} +/* }}} */ + /* hashes */ /* {{{ proto long Redis::hset(string key, string mem, string val) */ diff --git a/redis_cluster.c b/redis_cluster.c index eb4726a3..7087e478 100644 --- a/redis_cluster.c +++ b/redis_cluster.c @@ -274,6 +274,8 @@ zend_function_entry redis_cluster_functions[] = { PHP_ME(RedisCluster, zincrby, arginfo_zincrby, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zinterstore, arginfo_zstore, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zlexcount, arginfo_key_min_max, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, zpopmax, arginfo_key, ZEND_ACC_PUBLIC) + PHP_ME(RedisCluster, zpopmin, arginfo_key, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zrange, arginfo_zrange, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zrangebylex, arginfo_zrangebylex, ZEND_ACC_PUBLIC) PHP_ME(RedisCluster, zrangebyscore, arginfo_zrangebyscore, ZEND_ACC_PUBLIC) @@ -1844,6 +1846,30 @@ PHP_METHOD(RedisCluster, zremrangebylex) { } /* }}} */ +/* {{{ proto array RedisCluster::zpopmax(string key) */ +PHP_METHOD(RedisCluster, zpopmax) { + if (ZEND_NUM_ARGS() == 1) { + CLUSTER_PROCESS_KW_CMD("ZPOPMAX", redis_key_cmd, cluster_mbulk_resp, 0); + } else if (ZEND_NUM_ARGS() == 2) { + CLUSTER_PROCESS_KW_CMD("ZPOPMAX", redis_key_long_cmd, cluster_mbulk_resp, 0); + } else { + ZEND_WRONG_PARAM_COUNT(); + } +} +/* }}} */ + +/* {{{ proto array RedisCluster::zpopmin(string key) */ +PHP_METHOD(RedisCluster, zpopmin) { + if (ZEND_NUM_ARGS() == 1) { + CLUSTER_PROCESS_KW_CMD("ZPOPMIN", redis_key_cmd, cluster_mbulk_resp, 0); + } else if (ZEND_NUM_ARGS() == 2) { + CLUSTER_PROCESS_KW_CMD("ZPOPMIN", redis_key_long_cmd, cluster_mbulk_resp, 0); + } else { + ZEND_WRONG_PARAM_COUNT(); + } +} +/* }}} */ + /* {{{ proto RedisCluster::sort(string key, array options) */ PHP_METHOD(RedisCluster, sort) { redisCluster *c = GET_CONTEXT(); diff --git a/redis_cluster.h b/redis_cluster.h index 8995cc19..5e928174 100644 --- a/redis_cluster.h +++ b/redis_cluster.h @@ -224,6 +224,8 @@ PHP_METHOD(RedisCluster, restore); PHP_METHOD(RedisCluster, setrange); PHP_METHOD(RedisCluster, smove); PHP_METHOD(RedisCluster, srandmember); +PHP_METHOD(RedisCluster, zpopmin); +PHP_METHOD(RedisCluster, zpopmax); PHP_METHOD(RedisCluster, zrange); PHP_METHOD(RedisCluster, zrevrange); PHP_METHOD(RedisCluster, zrangebyscore); diff --git a/tests/RedisTest.php b/tests/RedisTest.php index 75fade20..e666b1fc 100644 --- a/tests/RedisTest.php +++ b/tests/RedisTest.php @@ -2409,6 +2409,29 @@ class Redis_Test extends TestSuite $this->assertEquals($this->redis->zRemRangeByLex('key', '[a', '[c'), 2); } + public function testZPop() { + if (version_compare($this->version, "5.0.0", "lt")) { + $this->MarkTestSkipped(); + return; + } + + // zPopMax and zPopMin without a COUNT argument + $this->redis->del('key'); + $this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e'); + $this->assertTrue(array('e', '4') === $this->redis->zPopMax('key')); + $this->assertTrue(array('a', '0') === $this->redis->zPopMin('key')); + + // zPopMax with a COUNT argument + $this->redis->del('key'); + $this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e'); + $this->assertTrue(array('e', '4', 'd', '3', 'c', '2') === $this->redis->zPopMax('key', 3)); + + // zPopMin with a COUNT argument + $this->redis->del('key'); + $this->redis->zAdd('key', 0, 'a', 1, 'b', 2, 'c', 3, 'd', 4, 'e'); + $this->assertTrue(array('a', '0', 'b', '1', 'c', '2') === $this->redis->zPopMin('key', 3)); + } + public function testHashes() { $this->redis->del('h', 'key'); $this->assertTrue(0 === $this->redis->hLen('h')); |