Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f968c17

Browse files
committed
Made ZREM variadic.
1 parent 331f405 commit f968c17

File tree

2 files changed

+12
-24
lines changed

2 files changed

+12
-24
lines changed

redis.c

+4-24
Original file line numberDiff line numberDiff line change
@@ -3249,36 +3249,16 @@ PHP_METHOD(Redis, zRange)
32493249
*/
32503250
PHP_METHOD(Redis, zDelete)
32513251
{
3252-
zval *object;
32533252
RedisSock *redis_sock;
3254-
char *key = NULL, *val = NULL, *cmd;
3255-
int key_len, val_len, cmd_len;
3256-
int val_free, key_free = 0;
3257-
zval *z_value;
32583253

3259-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz",
3260-
&object, redis_ce, &key, &key_len,
3261-
&z_value) == FAILURE) {
3262-
RETURN_FALSE;
3263-
}
3264-
3265-
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
3266-
RETURN_FALSE;
3267-
}
3268-
3269-
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
3270-
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
3271-
cmd_len = redis_cmd_format_static(&cmd, "ZREM", "ss", key, key_len, val, val_len);
3272-
if(val_free) efree(val);
3273-
if(key_free) efree(key);
3254+
generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
3255+
"ZREM", sizeof("ZREM") - 1,
3256+
2, &redis_sock, 0, 0);
32743257

3275-
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
32763258
IF_ATOMIC() {
3277-
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
3259+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
32783260
}
32793261
REDIS_PROCESS_RESPONSE(redis_long_response);
3280-
3281-
32823262
}
32833263
/* }}} */
32843264
/* {{{ proto long Redis::zDeleteRangeByScore(string key, string start, string end)

tests/TestRedis.php

+8
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,14 @@ private function checkSerializer($mode) {
26522652
$this->assertTrue(1 === $this->redis->zDelete('key', $z[3]));
26532653
$this->assertTrue(0 === $this->redis->zDelete('key', $z[3]));
26542654
unset($z[3]);
2655+
// variadic
2656+
$this->redis->delete('k');
2657+
$this->redis->zAdd('k', 0, 'a');
2658+
$this->redis->zAdd('k', 1, 'b');
2659+
$this->redis->zAdd('k', 2, 'c');
2660+
$this->assertTrue(2 === $this->redis->zDelete('k', 'a', 'c'));
2661+
$this->assertTrue(1.0 === $this->redis->zScore('k', 'b'));
2662+
$this->assertTrue($this->redis->zRange('k', 0, -1, true) == array('b' => 1.0));
26552663

26562664
// zRange
26572665
$this->assertTrue($z === $this->redis->zRange('key', 0, -1));

0 commit comments

Comments
 (0)