10000 DUMP, RESTORE commands · jrtkcoder/phpredis@d18388b · GitHub
[go: up one dir, main page]

Skip to content

Commit d18388b

Browse files
DUMP, RESTORE commands
1 parent 96af61b commit d18388b

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

php_redis.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ PHP_METHOD(Redis, object);
130130
PHP_METHOD(Redis, eval);
131131
PHP_METHOD(Redis, evalsha);
132132
PHP_METHOD(Redis, script);
133+
PHP_METHOD(Redis, dump);
134+
PHP_METHOD(Redis, restore);
133135

134136
PHP_METHOD(Redis, mset);
135137
PHP_METHOD(Redis, msetnx);

redis.c

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ static zend_function_entry redis_functions[] = {
154154
PHP_ME(Redis, bgrewriteaof, NULL, ZEND_ACC_PUBLIC)
155155
PHP_ME(Redis, slaveof, NULL, ZEND_ACC_PUBLIC)
156156
PHP_ME(Redis, object, NULL, ZEND_ACC_PUBLIC)
157+
157158
PHP_ME(Redis, eval, NULL, ZEND_ACC_PUBLIC)
158159
PHP_ME(Redis, evalsha, NULL, ZEND_ACC_PUBLIC)
159160
PHP_ME(Redis, script, NULL, ZEND_ACC_PUBLIC)
161+
PHP_ME(Redis, dump, NULL, ZEND_ACC_PUBLIC)
162+
PHP_ME(Redis, restore, NULL, ZEND_ACC_PUBLIC)
160163

161164
/* 1.1 */
162165
PHP_ME(Redis, mset, NULL, ZEND_ACC_PUBLIC)
@@ -5796,10 +5799,10 @@ PHP_METHOD(Redis, script) {
57965799
// Grab the number of arguments
57975800
argc = ZEND_NUM_ARGS();
57985801

5799-
// Allocate aan array big enough to store our arguments, and grab them
5802+
// Allocate an array big enough to store our arguments
58005803
z_args = emalloc(argc * sizeof(zval*));
58015804

5802-
// Make sure we can grab our arguments, we have a directive (that is a string), and the directive is one we know about
5805+
// Make sure we can grab our arguments, we have a string directive
58035806
if(zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
58045807
(argc < 1 || Z_TYPE_P(z_args[0]) != IS_STRING))
58055808
{
@@ -5842,5 +5845,71 @@ PHP_METHOD(Redis, script) {
58425845
REDIS_PROCESS_RESPONSE(redis_read_variant_reply);
58435846
}
58445847

5848+
/* {{{ proto DUMP key
5849+
*/
5850+
PHP_METHOD(Redis, dump) {
5851+
zval *object;
5852+
RedisSock *redis_sock;
5853+
char *cmd, *key;
5854+
int cmd_len, key_len, key_free;
5855+
5856+
// Parse our arguments
5857+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os", &object, redis_ce,
5858+
&key, &key_len) == FAILURE) {
5859+
RETURN_FALSE;
5860+
}
5861+
5862+
// Grab our socket
5863+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
5864+
RETURN_FALSE;
5865+
}
5866+
5867+
// Prefix our key if we need to
5868+
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
5869+
cmd_len = redis_cmd_format_static(&cmd, "DUMP", "s", key, key_len);
5870+
if(key_free) efree(key);
5871+
5872+
// Kick off our request
5873+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
5874+
IF_ATOMIC() {
5875+
redis_string_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
5876+
}
5877+
REDIS_PROCESS_RESPONSE(redis_string_response);
5878+
}
5879+
5880+
/*
5881+
* {{{ proto RESTORE ttl key value
5882+
*/
5883+
PHP_METHOD(Redis, restore) {
5884+
zval *object;
5885+
RedisSock *redis_sock;
5886+
char *cmd, *key, *value;
5887+
int cmd_len, key_len, value_len, key_free;
5888+
long ttl;
5889+
5890+
// Parse our arguments
5891+
if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osls", &object, redis_ce,
5892+
&key, &key_len, &ttl, &value, &value_len) == FAILURE) {
5893+
RETURN_FALSE;
5894+
}
5895+
5896+
// Grab our socket
5897+
if(redis_sock_get(object, &redis_sock TSRMLS_CC, 0) < 0) {
5898+
RETURN_FALSE;
5899+
}
5900+
5901+
// Prefix the key if we need to
5902+
key_free = redis_key_prefix(redis_sock, &key, &key_len TSRMLS_CC);
5903+
cmd_len = redis_cmd_format_static(&cmd, "RESTORE", "sls", key, key_len, ttl, value, value_len);
5904+
if(key_free) efree(key);
5905+
5906+
// Kick off our restore request
5907+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
5908+
IF_ATOMIC() {
5909+
redis_boolean_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
5910+
}
5911+
REDIS_PROCESS_RESPONSE(redis_boolean_response);
5912+
}
5913+
58455914
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
58465915

0 commit comments

Comments
 (0)
0