8000 Made LPUSH/RPUSH variadic. · jrtkcoder/phpredis@9708eab · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9708eab

Browse files
committed
Made LPUSH/RPUSH variadic.
1 parent f968c17 commit 9708eab

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

redis.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,15 +1383,31 @@ generic_push_function(INTERNAL_FUNCTION_PARAMETERS, char *keyword, int keyword_l
13831383
*/
13841384
PHP_METHOD(Redis, lPush)
13851385
{
1386-
generic_push_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "LPUSH", sizeof("LPUSH")-1);
1386+
RedisSock *redis_sock;
1387+
1388+
generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
1389+
"LPUSH", sizeof("LPUSH") - 1,
1390+
2, &redis_sock, 0, 0);
1391+
IF_ATOMIC() {
1392+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
1393+
}
1394+
REDIS_PROCESS_RESPONSE(redis_long_response);
13871395
}
13881396
/* }}} */
13891397

13901398
/* {{{ proto boolean Redis::rPush(string key , string value)
13911399
*/
13921400
PHP_METHOD(Redis, rPush)
13931401
{
1394-
generic_push_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "RPUSH", sizeof("RPUSH")-1);
1402+
RedisSock *redis_sock;
1403+
1404+
generic_multiple_args_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,
1405+
"RPUSH", sizeof("RPUSH") - 1,
1406+
2, &redis_sock, 0, 0);
1407+
IF_ATOMIC() {
1408+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
1409+
}
1410+
REDIS_PROCESS_RESPONSE(redis_long_response);
13951411
}
13961412
/* }}} */
13971413

tests/TestRedis.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,14 @@ public function testRename() {
212212
$this->assertTrue($this->redis->lGetRange('key0', 0, -1) === array());
213213
$this->assertTrue($this->redis->lGetRange('key1', 0, -1) === array('val1', 'val0'));
214214

215+
// variadic
216+
$this->redis->delete('key0');
217+
$this->assertTrue(3 === $this->redis->lPush('key0', 'val0', 'val1', 'val2'));
218+
$this->assertTrue(array('val2', 'val1', 'val0') === $this->redis->lrange('key0', 0, -1));
219+
220+
$this->redis->delete('key0');
221+
$this->assertTrue(3 === $this->redis->rPush('key0', 'val0', 'val1', 'val2'));
222+
$this->assertTrue(array('val0', 'val1', 'val2') === $this->redis->lrange('key0', 0, -1));
215223
}
216224

217225
public function testRenameNx() {

0 commit comments

Comments
 (0)
0