Skip to content

Commit 8283007

Browse files
MIGRAGE command
1 parent e15fcfc commit 8283007

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

php_redis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ PHP_METHOD(Redis, evalsha);
134134
PHP_METHOD(Redis, script);
135135
PHP_METHOD(Redis, dump);
136136
PHP_METHOD(Redis, restore);
137+
PHP_METHOD(Redis, migrate);
137138

138139
PHP_METHOD(Redis, getLastError);
139-
140140
PHP_METHOD(Redis, _prefix);
141141
PHP_METHOD(Redis, _unserialize);
142142

redis.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ static zend_function_entry redis_functions[] = {
162162
PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
163163
PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
164164
PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
165+
PHP_ME(Redis, migrate, NULL, ZEND_ACC_PUBLIC)
165166

166167
PHP_ME(Redis, getLastError, NULL, ZEND_ACC_PUBLIC)
167168

@@ -6026,6 +6027,39 @@ PHP_METHOD(Redis, restore) {
60266027
REDIS_PROCESS_RESPONSE(redis_boolean_response);
60276028
}
60286029

6030+
/*
6031+
* {{{ proto Redis::migrate(host port key dest-db timeout)
6032+
*/
6033+
PHP_METHOD(Redis, migrate) {
6034+
zval *object;
6035+
RedisSock *redis_sock;
6036+
char *cmd, *host, *key;
6037+
int cmd_len, host_len, key_len, port, dest_db, timeout, key_free;
6038+
6039+
// Parse arguments
6040+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_C, getThis(), "Oslsll", &object, redis_ce,
6041+
&host, &host_len, &port, &key, &key_len, &dest_db, &timeout) == FAILURE) {
6042+
RETURN_FALSE;
6043+
}
6044+
6045+
// Grabg our socket
6046+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
6047+
RETURN_FALSE;
6048+
}
6049+
6050+
// Prefix our key if we need to, build our command
6051+
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
6052+
cmd_len = redis_cmd_format_static(&cmd, "MIGRATE", "sdsdd", host, host_len, port, key, key_len, dest_db, timeout);
6053+
if(key_free) efree(key);
6054+
6055+
// Kick off our MIGRATE request
6056+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
6057+
IF_ATOMIC() {
6058+
redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
6059+
}
6060+
REDIS_PROCESS_RESPONSE(redis_boolean_response);
6061+
}
6062+
60296063
/*
60306064
* {{{ proto Redis::_prefix(key)
60316065
*/

0 commit comments

Comments
 (0)