10000 Made SREM variadic · jrtkcoder/phpredis@331f405 · GitHub
[go: up one dir, main page]

Skip to content

Commit 331f405

Browse files
committed
Made SREM variadic
1 parent 1fb9404 commit 331f405

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

redis.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,34 +1760,16 @@ PHP_METHOD(Redis, sSize)
17601760
*/
17611761
PHP_METHOD(Redis, sRemove)
17621762
{
1763-
zval *object;
17641763
RedisSock *redis_sock;
1765-
char *key = NULL, *val = NULL, *cmd;
1766-
int key_len, val_len, cmd_len;
1767-
int val_free, key_free = 0;
1768-
zval *z_value;
1769-
1770-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osz",
1771-
&object, redis_ce,
1772-
&key, &key_len, &z_value) == FAILURE) {
1773-
RETURN_FALSE;
1774-
}
1775-
1776-
if (redis_sock_get(object, &redis_sock TSRMLS_CC) < 0) {
1777-
RETURN_FALSE;
1778-
}
17791764

1780-
val_free = redis_serialize(redis_sock, z_value, &val, &val_len TSRMLS_CC);
1781-
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
1782-
cmd_len = redis_cmd_format_static(&cmd, "SREM", "ss", key, key_len, val, val_len);
1783-
if(val_free) efree(val);
1784-
if(key_free) efree(key);
1765+
generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
1766+
"SREM", sizeof("SREM") - 1,
1767+
2, &redis_sock, 0, 0);
17851768

1786-
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
17871769
IF_ATOMIC() {
1788-
redis_1_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
1770+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
17891771
}
1790-
REDIS_PROCESS_RESPONSE(redis_1_response);
1772+
REDIS_PROCESS_RESPONSE(redis_long_response);
17911773
}
17921774
/* }}} */
17931775
/* {{{ proto boolean Redis::sMove(string set_src, string set_dst, mixed value)

tests/TestRedis.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,7 +2370,7 @@ protected function sequence($mode) {
23702370
$this->assertTrue($ret[$i++] === 1); // skey2 now has 2 elements.
23712371

23722372
$this->assertTrue($ret[$i++] === 4);
2373-
$this->assertTrue($ret[$i++] === TRUE); // we did remove that value.
2373+
$this->assertTrue($ret[$i++] === 1); // we did remove that value.
23742374
$this->assertTrue($ret[$i++] === 3); // now 3 values only.
23752375
$this->assertTrue($ret[$i++] === TRUE); // the move did succeed.
23762376
$this->assertTrue($ret[$i++] === 3); // sKey2 now has 3 values.
@@ -2614,8 +2614,14 @@ private function checkSerializer($mode) {
26142614
$this->assertTrue(1 === $this->redis->sAdd('k', 'a', 'b', 'c', 'd'));
26152615

26162616
// sRemove
2617-
$this->assertTrue(TRUE === $this->redis->sRemove('key', $s[3]));
2618-
$this->assertTrue(FALSE === $this->redis->sRemove('key', $s[3]));
2617+
$this->assertTrue(1 === $this->redis->sRemove('key', $s[3]));
2618+
$this->assertTrue(0 === $this->redis->sRemove('key', $s[3]));
2619+
// variadic
2620+
$this->redis->delete('k');
2621+
$this->redis->sAdd('k', 'a', 'b', 'c', 'd');
2622+
$this->assertTrue(2 === $this->redis->sRem('k', 'a', 'd'));
2623+
$this->assertTrue(2 === $this->redis->sRem('k', 'b', 'c', 'e'));
2624+
$this->assertTrue(FALSE === $this->redis->exists('k'));
26192625

26202626
// sContains
26212627
$this->assertTrue(TRUE === $this->redis->sContains('key', $s[0]));

0 commit comments

Comments
 (0)
0