Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.h5
-rw-r--r--php_redis.h1
-rw-r--r--redis.c6
-rw-r--r--redis_commands.c18
-rw-r--r--redis_commands.h3
-rw-r--r--tests/RedisClusterTest.php1
-rw-r--r--tests/RedisTest.php5
7 files changed, 39 insertions, 0 deletions
diff --git a/common.h b/common.h
index 4d3977f8..4b1342df 100644
--- a/common.h
+++ b/common.h
@@ -782,6 +782,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_key_offset_value, 0, 0, 3)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_swapdb, 0, 0, 2)
+ ZEND_ARG_INFO(0, srcdb)
+ ZEND_ARG_INFO(0, dstdb)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_key_start_end, 0, 0, 3)
ZEND_ARG_INFO(0, key)
ZEND_ARG_INFO(0, start)
diff --git a/php_redis.h b/php_redis.h
index 895ad710..2d62d81d 100644
--- a/php_redis.h
+++ b/php_redis.h
@@ -108,6 +108,7 @@ PHP_METHOD(Redis, pttl);
PHP_METHOD(Redis, persist);
PHP_METHOD(Redis, info);
PHP_METHOD(Redis, select);
+PHP_METHOD(Redis, swapdb);
PHP_METHOD(Redis, move);
PHP_METHOD(Redis, zAdd);
PHP_METHOD(Redis, zDelete);
diff --git a/redis.c b/redis.c
index c226a48d..e267d2c8 100644
--- a/redis.c
+++ b/redis.c
@@ -387,6 +387,7 @@ static zend_function_entry redis_functions[] = {
PHP_ME(Redis, sscan, arginfo_kscan, ZEND_ACC_PUBLIC)
PHP_ME(Redis, strlen, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, subscribe, arginfo_subscribe, ZEND_ACC_PUBLIC)
+ PHP_ME(Redis, swapdb, arginfo_swapdb, ZEND_ACC_PUBLIC)
PHP_ME(Redis, time, arginfo_void, ZEND_ACC_PUBLIC)
PHP_ME(Redis, ttl, arginfo_key, ZEND_ACC_PUBLIC)
PHP_ME(Redis, type, arginfo_key, ZEND_ACC_PUBLIC)
@@ -1832,6 +1833,11 @@ PHP_METHOD(Redis, select) {
}
/* }}} */
+/* {{{ proto bool Redis::swapdb(long srcdb, long dstdb) */
+PHP_METHOD(Redis, swapdb) {
+ REDIS_PROCESS_KW_CMD("SWAPDB", redis_long_long_cmd, redis_boolean_response);
+}
+
/* {{{ proto bool Redis::move(string key, long dbindex) */
PHP_METHOD(Redis, move) {
REDIS_PROCESS_KW_CMD("MOVE", redis_key_long_cmd, redis_1_response);
diff --git a/redis_commands.c b/redis_commands.c
index ac0ed30d..708d9361 100644
--- a/redis_commands.c
+++ b/redis_commands.c
@@ -333,6 +333,24 @@ int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return SUCCESS;
}
+/* long, long */
+int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
+ char *kw, char **cmd, int *cmd_len, short *slot,
+ void **ctx)
+{
+ zend_long v1, v2;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &v1, &v2)
+ == FAILURE)
+ {
+ return FAILURE;
+ }
+
+ *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "ll", v1, v2);
+
+ return SUCCESS;
+}
+
/* key, long, long */
int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot,
diff --git a/redis_commands.h b/redis_commands.h
index 51d0b9f1..255a992e 100644
--- a/redis_commands.h
+++ b/redis_commands.h
@@ -64,6 +64,9 @@ int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
+int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
+ char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
+
int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot, void **ctx);
diff --git a/tests/RedisClusterTest.php b/tests/RedisClusterTest.php
index d03d3591..4e0c15eb 100644
--- a/tests/RedisClusterTest.php
+++ b/tests/RedisClusterTest.php
@@ -34,6 +34,7 @@ class Redis_Cluster_Test extends Redis_Test {
public function testReconnectSelect() { return $this->markTestSkipped(); }
public function testMultipleConnect() { return $this->markTestSkipped(); }
public function testDoublePipeNoOp() { return $this->markTestSkipped(); }
+ public function testSwapDB() { return $this->markTestSkipped(); }
/* Load our seeds on construction */
public function __construct() {
diff --git a/tests/RedisTest.php b/tests/RedisTest.php
index f2ec3015..2dafb581 100644
--- a/tests/RedisTest.php
+++ b/tests/RedisTest.php
@@ -1903,6 +1903,11 @@ class Redis_Test extends TestSuite
$this->assertTrue($this->redis->select(0));
}
+ public function testSwapDB() {
+ $this->assertTrue($this->redis->swapdb(0, 1));
+ $this->assertTrue($this->redis->swapdb(0, 1));
+ }
+
public function testMset() {
$this->redis->del('x', 'y', 'z'); // remove x y z
$this->assertTrue($this->redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'))); // set x y z