Skip to content

Commit 625fade

Browse files
Merge branch 'swapdb-command' into develop
2 parents 6028df5 + 03f7701 commit 625fade

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_key_offset_value, 0, 0, 3)
782782
ZEND_ARG_INFO(0, value)
783783
ZEND_END_ARG_INFO()
784784

785+
ZEND_BEGIN_ARG_INFO_EX(arginfo_swapdb, 0, 0, 2)
786+
ZEND_ARG_INFO(0, srcdb)
787+
ZEND_ARG_INFO(0, dstdb)
788+
ZEND_END_ARG_INFO()
789+
785790
ZEND_BEGIN_ARG_INFO_EX(arginfo_key_start_end, 0, 0, 3)
786791
ZEND_ARG_INFO(0, key)
787792
ZEND_ARG_INFO(0, start)

php_redis.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ PHP_METHOD(Redis, pttl);
109109
PHP_METHOD(Redis, persist);
110110
PHP_METHOD(Redis, info);
111111
PHP_METHOD(Redis, select);
112+
PHP_METHOD(Redis, swapdb);
112113
PHP_METHOD(Redis, move);
113114
PHP_METHOD(Redis, zAdd);
114115
PHP_METHOD(Redis, zDelete);

redis.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static zend_function_entry redis_functions[] = {
387387
PHP_ME(Redis, sscan, arginfo_kscan, ZEND_ACC_PUBLIC)
388388
PHP_ME(Redis, strlen, arginfo_key, ZEND_ACC_PUBLIC)
389389
PHP_ME(Redis, subscribe, arginfo_subscribe, ZEND_ACC_PUBLIC)
390+
PHP_ME(Redis, swapdb, arginfo_swapdb, ZEND_ACC_PUBLIC)
390391
PHP_ME(Redis, time, arginfo_void, ZEND_ACC_PUBLIC)
391392
PHP_ME(Redis, ttl, arginfo_key, ZEND_ACC_PUBLIC)
392393
PHP_ME(Redis, type, arginfo_key, ZEND_ACC_PUBLIC)
@@ -1841,6 +1842,11 @@ PHP_METHOD(Redis, select) {
18411842
}
18421843
/* }}} */
18431844

1845+
/* {{{ proto bool Redis::swapdb(long srcdb, long dstdb) */
1846+
PHP_METHOD(Redis, swapdb) {
1847+
REDIS_PROCESS_KW_CMD("SWAPDB", redis_long_long_cmd, redis_boolean_response);
1848+
}
1849+
18441850
/* {{{ proto bool Redis::move(string key, long dbindex) */
18451851
PHP_METHOD(Redis, move) {
18461852
REDIS_PROCESS_KW_CMD("MOVE", redis_key_long_cmd, redis_1_response);

redis_commands.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,24 @@ int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
333333
return SUCCESS;
334334
}
335335

336+
/* long, long */
337+
int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
338+
char *kw, char **cmd, int *cmd_len, short *slot,
339+
void **ctx)
340+
{
341+
zend_long v1, v2;
342+
343+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &v1, &v2)
344+
== FAILURE)
345+
{
346+
return FAILURE;
347+
}
348+
349+
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "ll", v1, v2);
350+
351+
return SUCCESS;
352+
}
353+
336354
/* key, long, long */
337355
int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
338356
char *kw, char **cmd, int *cmd_len, short *slot,

redis_commands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
6464
int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
6565
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
6666

67+
int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
68+
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
69+
6770
int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
6871
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
6972

tests/RedisClusterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testSelect() { return $this->markTestSkipped(); }
3434
public function testReconnectSelect() { return $this->markTestSkipped(); }
3535
public function testMultipleConnect() { return $this->markTestSkipped(); }
3636
public function testDoublePipeNoOp() { return $this->markTestSkipped(); }
37+
public function testSwapDB() { return $this->markTestSkipped(); }
3738

3839
/* Load our seeds on construction */
3940
public function __construct() {

tests/RedisTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,15 @@ public function testSelect() {
19141914
$this->assertTrue($this->redis->select(0));
19151915
}
19161916

1917+
public function testSwapDB() {
1918+
if (version_compare($this->version, "4.0.0", "lt")) {
1919+
$this->markTestSkipped();
1920+
}
1921+
1922+
$this->assertTrue($this->redis->swapdb(0, 1));
1923+
$this->assertTrue($this->redis->swapdb(0, 1));
1924+
}
1925+
19171926
public function testMset() {
19181927
$this->redis->del('x', 'y', 'z'); // remove x y z
19191928
$this->assertTrue($this->redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'))); // set x y z

0 commit comments

Comments
 (0)