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--library.c129
-rw-r--r--redis.c58
-rw-r--r--redis_array.c1150
-rw-r--r--redis_array.h26
-rw-r--r--redis_array_impl.c812
-rw-r--r--redis_cluster.c46
6 files changed, 1111 insertions, 1110 deletions
diff --git a/library.c b/library.c
index 84ed318b..e91ab0ab 100644
--- a/library.c
+++ b/library.c
@@ -1517,16 +1517,17 @@ PHP_REDIS_API int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
redis_sock->dbNumber = 0;
if (redis_sock->stream != NULL) {
- redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
- redis_sock->watching = 0;
+ redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
+ redis_sock->watching = 0;
- /* Stil valid? */
- if (!redis_sock->persistent) {
- php_stream_close(redis_sock->stream);
- }
- redis_sock->stream = NULL;
+ /* Stil valid? */
+ if (!redis_sock->persistent) {
+ php_stream_close(redis_sock->stream);
+ }
- return 1;
+ redis_sock->stream = NULL;
+
+ return 1;
}
return 0;
@@ -1967,12 +1968,12 @@ redis_sock_gets(RedisSock *redis_sock, char *buf, int buf_size,
return -1;
}
- /* We don't need \r\n */
- *line_size-=2;
- buf[*line_size]='\0';
+ /* We don't need \r\n */
+ *line_size-=2;
+ buf[*line_size]='\0';
- /* Success! */
- return 0;
+ /* Success! */
+ return 0;
}
PHP_REDIS_API int
@@ -2001,17 +2002,17 @@ redis_read_reply_type(RedisSock *redis_sock, REDIS_REPLY_TYPE *reply_type,
// Buffer to hold size information
char inbuf[255];
- /* Read up to our newline */
- if(php_stream_gets(redis_sock->stream, inbuf, sizeof(inbuf)) == NULL) {
- return -1;
- }
+ /* Read up to our newline */
+ if (php_stream_gets(redis_sock->stream, inbuf, sizeof(inbuf)) == NULL) {
+ return -1;
+ }
- /* Set our size response */
- *reply_info = atol(inbuf);
- }
+ /* Set our size response */
+ *reply_info = atol(inbuf);
+ }
- /* Success! */
- return 0;
+ /* Success! */
+ return 0;
}
/*
@@ -2025,26 +2026,26 @@ redis_read_variant_line(RedisSock *redis_sock, REDIS_REPLY_TYPE reply_type,
char inbuf[4096];
size_t line_size;
- /* Attempt to read our single line reply */
- if(redis_sock_gets(redis_sock, inbuf, sizeof(inbuf), &line_size TSRMLS_CC) < 0) {
- return -1;
- }
+ /* Attempt to read our single line reply */
+ if(redis_sock_gets(redis_sock, inbuf, sizeof(inbuf), &line_size TSRMLS_CC) < 0) {
+ return -1;
+ }
// If this is an error response, check if it is a SYNC error, and throw in
// that case
if(reply_type == TYPE_ERR) {
- /* Set our last error */
- redis_sock_set_err(redis_sock, inbuf, line_size);
+ /* Set our last error */
+ redis_sock_set_err(redis_sock, inbuf, line_size);
/* Handle throwable errors */
redis_error_throw(redis_sock TSRMLS_CC);
- /* Set our response to FALSE */
- ZVAL_FALSE(z_ret);
- } else {
- /* Set our response to TRUE */
- ZVAL_TRUE(z_ret);
- }
+ /* Set our response to FALSE */
+ ZVAL_FALSE(z_ret);
+ } else {
+ /* Set our response to TRUE */
+ ZVAL_TRUE(z_ret);
+ }
return 0;
}
@@ -2056,11 +2057,11 @@ redis_read_variant_bulk(RedisSock *redis_sock, int size, zval *z_ret
// Attempt to read the bulk reply
char *bulk_resp = redis_sock_read_bulk_reply(redis_sock, size TSRMLS_CC);
- /* Set our reply to FALSE on failure, and the string on success */
- if(bulk_resp == NULL) {
- ZVAL_FALSE(z_ret);
- return -1;
- }
+ /* Set our reply to FALSE on failure, and the string on success */
+ if(bulk_resp == NULL) {
+ ZVAL_FALSE(z_ret);
+ return -1;
+ }
ZVAL_STRINGL(z_ret, bulk_resp, size);
efree(bulk_resp);
return 0;
@@ -2126,9 +2127,9 @@ redis_read_multibulk_recursive(RedisSock *redis_sock, int elements, zval *z_ret
break;
}
- /* Decrement our element counter */
- elements--;
- }
+ /* Decrement our element counter */
+ elements--;
+ }
return 0;
}
@@ -2152,21 +2153,21 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
#if (PHP_MAJOR_VERSION < 7)
MAKE_STD_ZVAL(z_ret);
#endif
- /* Switch based on our top level reply type */
- switch(reply_type) {
- case TYPE_ERR:
- case TYPE_LINE:
- redis_read_variant_line(redis_sock, reply_type, z_ret TSRMLS_CC);
- break;
- case TYPE_INT:
- ZVAL_LONG(z_ret, reply_info);
- break;
- case TYPE_BULK:
- redis_read_variant_bulk(redis_sock, reply_info, z_ret TSRMLS_CC);
- break;
- case TYPE_MULTIBULK:
- /* Initialize an array for our multi-bulk response */
- array_init(z_ret);
+ /* Switch based on our top level reply type */
+ switch(reply_type) {
+ case TYPE_ERR:
+ case TYPE_LINE:
+ redis_read_variant_line(redis_sock, reply_type, z_ret TSRMLS_CC);
+ break;
+ case TYPE_INT:
+ ZVAL_LONG(z_ret, reply_info);
+ break;
+ case TYPE_BULK:
+ redis_read_variant_bulk(redis_sock, reply_info, z_ret TSRMLS_CC);
+ break;
+ case TYPE_MULTIBULK:
+ /* Initialize an array for our multi-bulk response */
+ array_init(z_ret);
// If we've got more than zero elements, parse our multi bulk
// response recursively
@@ -2185,15 +2186,15 @@ redis_read_variant_reply(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
return FAILURE;
}
- IF_NOT_ATOMIC() {
- add_next_index_zval(z_tab, z_ret);
- } else {
- /* Set our return value */
+ IF_NOT_ATOMIC() {
+ add_next_index_zval(z_tab, z_ret);
+ } else {
+ /* Set our return value */
RETVAL_ZVAL(z_ret, 0, 1);
- }
+ }
- /* Success */
- return 0;
+ /* Success */
+ return 0;
}
/* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */
diff --git a/redis.c b/redis.c
index 70000a2b..e2432005 100644
--- a/redis.c
+++ b/redis.c
@@ -2895,7 +2895,7 @@ PHP_METHOD(Redis, evalsha) {
PHP_REDIS_API int
redis_build_script_exists_cmd(char **ret, zval *argv, int argc) {
- smart_string cmd = {0};
+ smart_string cmd = {0};
zend_string *zstr;
int i;
@@ -2909,9 +2909,9 @@ redis_build_script_exists_cmd(char **ret, zval *argv, int argc) {
zend_string_release(zstr);
}
- /* Success */
+ /* Success */
*ret = cmd.c;
- return cmd.len;
+ return cmd.len;
}
/* {{{ proto status Redis::script('flush')
@@ -2925,24 +2925,24 @@ PHP_METHOD(Redis, script) {
int cmd_len, argc;
char *cmd;
- /* Attempt to grab our socket */
+ /* Attempt to grab our socket */
if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL) {
- RETURN_FALSE;
- }
+ RETURN_FALSE;
+ }
- /* Grab the number of arguments */
- argc = ZEND_NUM_ARGS();
+ /* Grab the number of arguments */
+ argc = ZEND_NUM_ARGS();
- /* Allocate an array big enough to store our arguments */
- z_args = emalloc(argc * sizeof(zval));
+ /* Allocate an array big enough to store our arguments */
+ z_args = emalloc(argc * sizeof(zval));
- /* Make sure we can grab our arguments, we have a string directive */
- if (zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
- (argc < 1 || Z_TYPE(z_args[0]) != IS_STRING))
- {
- efree(z_args);
- RETURN_FALSE;
- }
+ /* Make sure we can grab our arguments, we have a string directive */
+ if (zend_get_parameters_array(ht, argc, z_args) == FAILURE ||
+ (argc < 1 || Z_TYPE(z_args[0]) != IS_STRING))
+ {
+ efree(z_args);
+ RETURN_FALSE;
+ }
// Branch based on the directive
if(!strcasecmp(Z_STRVAL(z_args[0]), "flush") ||
@@ -2964,17 +2964,17 @@ PHP_METHOD(Redis, script) {
// Format our SCRIPT LOAD command
cmd_len = REDIS_SPPRINTF(&cmd, "SCRIPT", "ss", "LOAD", 4, Z_STRVAL(z_args[1]),
Z_STRLEN(z_args[1]));
- } else if(!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
- /* Construct our SCRIPT EXISTS command */
- cmd_len = redis_build_script_exists_cmd(&cmd, &(z_args[1]), argc-1);
- } else {
- /* Unknown directive */
- efree(z_args);
- RETURN_FALSE;
- }
-
- /* Free our alocated arguments */
- efree(z_args);
+ } else if(!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
+ /* Construct our SCRIPT EXISTS command */
+ cmd_len = redis_build_script_exists_cmd(&cmd, &(z_args[1]), argc-1);
+ } else {
+ /* Unknown directive */
+ efree(z_args);
+ RETURN_FALSE;
+ }
+
+ /* Free our alocated arguments */
+ efree(z_args);
// Kick off our request
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
@@ -3066,7 +3066,7 @@ PHP_METHOD(Redis, getLastError) {
RETURN_FALSE;
}
- /* Return our last error or NULL if we don't have one */
+ /* Return our last error or NULL if we don't have one */
if (redis_sock->err) {
RETURN_STRINGL(ZSTR_VAL(redis_sock->err), ZSTR_LEN(redis_sock->err));
}
diff --git a/redis_array.c b/redis_array.c
index cd2f2453..52713063 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -47,24 +47,24 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_call, 0, 0, 2)
- ZEND_ARG_INFO(0, function_name)
- ZEND_ARG_INFO(0, arguments)
+ ZEND_ARG_INFO(0, function_name)
+ ZEND_ARG_INFO(0, arguments)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_target, 0, 0, 1)
- ZEND_ARG_INFO(0, key)
+ ZEND_ARG_INFO(0, key)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_instance, 0, 0, 1)
- ZEND_ARG_INFO(0, host)
+ ZEND_ARG_INFO(0, host)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_rehash, 0, 0, 0)
- ZEND_ARG_INFO(0, callable)
+ ZEND_ARG_INFO(0, callable)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_select, 0, 0, 1)
- ZEND_ARG_INFO(0, index)
+ ZEND_ARG_INFO(0, index)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_mget, 0, 0, 1)
@@ -259,59 +259,59 @@ redis_array_get(zval *id TSRMLS_DC)
Public constructor */
PHP_METHOD(RedisArray, __construct)
{
- zval *z0, z_fun, z_dist, *zpData, *z_opts = NULL;
- RedisArray *ra = NULL;
- zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
- HashTable *hPrev = NULL, *hOpts = NULL;
- long l_retry_interval = 0;
- zend_bool b_lazy_connect = 0;
- double d_connect_timeout = 0, read_timeout = 0.0;
+ zval *z0, z_fun, z_dist, *zpData, *z_opts = NULL;
+ RedisArray *ra = NULL;
+ zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
+ HashTable *hPrev = NULL, *hOpts = NULL;
+ long l_retry_interval = 0;
+ zend_bool b_lazy_connect = 0;
+ double d_connect_timeout = 0, read_timeout = 0.0;
redis_array_object *obj;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &z0, &z_opts) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &z0, &z_opts) == FAILURE) {
+ RETURN_FALSE;
+ }
ZVAL_NULL(&z_fun);
ZVAL_NULL(&z_dist);
- /* extract options */
- if(z_opts) {
- hOpts = Z_ARRVAL_P(z_opts);
+ /* extract options */
+ if(z_opts) {
+ hOpts = Z_ARRVAL_P(z_opts);
- /* extract previous ring. */
+ /* extract previous ring. */
if ((zpData = zend_hash_str_find(hOpts, "previous", sizeof("previous") - 1)) != NULL && Z_TYPE_P(zpData) == IS_ARRAY
&& zend_hash_num_elements(Z_ARRVAL_P(zpData)) != 0
) {
- /* consider previous array as non-existent if empty. */
+ /* consider previous array as non-existent if empty. */
hPrev = Z_ARRVAL_P(zpData);
- }
+ }
- /* extract function name. */
+ /* extract function name. */
if ((zpData = zend_hash_str_find(hOpts, "function", sizeof("function") - 1)) != NULL) {
ZVAL_ZVAL(&z_fun, zpData, 1, 0);
- }
+ }
- /* extract function name. */
+ /* extract function name. */
if ((zpData = zend_hash_str_find(hOpts, "distributor", sizeof("distributor") - 1)) != NULL) {
ZVAL_ZVAL(&z_dist, zpData, 1, 0);
- }
+ }
- /* extract index option. */
+ /* extract index option. */
if ((zpData = zend_hash_str_find(hOpts, "index", sizeof("index") - 1)) != NULL) {
b_index = zval_is_true(zpData);
- }
+ }
- /* extract autorehash option. */
+ /* extract autorehash option. */
if ((zpData = zend_hash_str_find(hOpts, "autorehash", sizeof("autorehash") - 1)) != NULL) {
b_autorehash = zval_is_true(zpData);
- }
+ }
- /* pconnect */
+ /* pconnect */
if ((zpData = zend_hash_str_find(hOpts, "pconnect", sizeof("pconnect") - 1)) != NULL) {
b_pconnect = zval_is_true(zpData);
- }
+ }
- /* extract retry_interval option. */
+ /* extract retry_interval option. */
if ((zpData = zend_hash_str_find(hOpts, "retry_interval", sizeof("retry_interval") - 1)) != NULL) {
if (Z_TYPE_P(zpData) == IS_LONG) {
l_retry_interval = Z_LVAL_P(zpData);
@@ -320,12 +320,12 @@ PHP_METHOD(RedisArray, __construct)
}
}
- /* extract lazy connect option. */
+ /* extract lazy connect option. */
if ((zpData = zend_hash_str_find(hOpts, "lazy_connect", sizeof("lazy_connect") - 1)) != NULL) {
b_lazy_connect = zval_is_true(zpData);
- }
-
- /* extract connect_timeout option */
+ }
+
+ /* extract connect_timeout option */
if ((zpData = zend_hash_str_find(hOpts, "connect_timeout", sizeof("connect_timeout") - 1)) != NULL) {
if (Z_TYPE_P(zpData) == IS_DOUBLE) {
d_connect_timeout = Z_DVAL_P(zpData);
@@ -346,111 +346,111 @@ PHP_METHOD(RedisArray, __construct)
read_timeout = atof(Z_STRVAL_P(zpData));
}
}
- }
+ }
- /* extract either name of list of hosts from z0 */
- switch(Z_TYPE_P(z0)) {
- case IS_STRING:
- ra = ra_load_array(Z_STRVAL_P(z0) TSRMLS_CC);
- break;
+ /* extract either name of list of hosts from z0 */
+ switch(Z_TYPE_P(z0)) {
+ case IS_STRING:
+ ra = ra_load_array(Z_STRVAL_P(z0) TSRMLS_CC);
+ break;
- case IS_ARRAY:
- ra = ra_make_array(Z_ARRVAL_P(z0), &z_fun, &z_dist, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout TSRMLS_CC);
- break;
+ case IS_ARRAY:
+ ra = ra_make_array(Z_ARRVAL_P(z0), &z_fun, &z_dist, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout TSRMLS_CC);
+ break;
- default:
- WRONG_PARAM_COUNT;
- }
+ default:
+ WRONG_PARAM_COUNT;
+ }
zval_dtor(&z_dist);
zval_dtor(&z_fun);
- if(ra) {
- ra->auto_rehash = b_autorehash;
- ra->connect_timeout = d_connect_timeout;
- if(ra->prev) ra->prev->auto_rehash = b_autorehash;
+ if(ra) {
+ ra->auto_rehash = b_autorehash;
+ ra->connect_timeout = d_connect_timeout;
+ if(ra->prev) ra->prev->auto_rehash = b_autorehash;
#if (PHP_MAJOR_VERSION < 7)
obj = (redis_array_object *)zend_objects_get_address(getThis() TSRMLS_CC);
#else
obj = (redis_array_object *)((char *)Z_OBJ_P(getThis()) - XtOffsetOf(redis_array_object, std));
#endif
obj->ra = ra;
- }
+ }
}
static void
ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, int cmd_len, zval *z_args, zval *z_new_target) {
- zval z_fun, *redis_inst, *z_callargs, *zp_tmp;
- char *key = NULL; /* set to avoid "unused-but-set-variable" */
- int i, key_len = 0, argc;
- HashTable *h_args;
- zend_bool b_write_cmd = 0;
+ zval z_fun, *redis_inst, *z_callargs, *zp_tmp;
+ char *key = NULL; /* set to avoid "unused-but-set-variable" */
+ int i, key_len = 0, argc;
+ HashTable *h_args;
+ zend_bool b_write_cmd = 0;
- h_args = Z_ARRVAL_P(z_args);
+ h_args = Z_ARRVAL_P(z_args);
if ((argc = zend_hash_num_elements(h_args)) == 0) {
RETURN_FALSE;
}
- if(ra->z_multi_exec) {
- redis_inst = ra->z_multi_exec; /* we already have the instance */
- } else {
- /* extract key and hash it. */
+ if(ra->z_multi_exec) {
+ redis_inst = ra->z_multi_exec; /* we already have the instance */
+ } else {
+ /* extract key and hash it. */
if ((zp_tmp = zend_hash_index_find(h_args, 0)) == NULL || Z_TYPE_P(zp_tmp) != IS_STRING) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find key");
- RETURN_FALSE;
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find key");
+ RETURN_FALSE;
}
key = Z_STRVAL_P(zp_tmp);
key_len = Z_STRLEN_P(zp_tmp);
- /* find node */
- redis_inst = ra_find_node(ra, key, key_len, NULL TSRMLS_CC);
- if(!redis_inst) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find any redis servers for this key.");
- RETURN_FALSE;
- }
- }
+ /* find node */
+ redis_inst = ra_find_node(ra, key, key_len, NULL TSRMLS_CC);
+ if(!redis_inst) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not find any redis servers for this key.");
+ RETURN_FALSE;
+ }
+ }
- /* pass call through */
- ZVAL_STRINGL(&z_fun, cmd, cmd_len); /* method name */
- z_callargs = ecalloc(argc, sizeof(zval));
+ /* pass call through */
+ ZVAL_STRINGL(&z_fun, cmd, cmd_len); /* method name */
+ z_callargs = ecalloc(argc, sizeof(zval));
- /* copy args to array */
+ /* copy args to array */
i = 0;
ZEND_HASH_FOREACH_VAL(h_args, zp_tmp) {
ZVAL_ZVAL(&z_callargs[i], zp_tmp, 1, 0);
i++;
} ZEND_HASH_FOREACH_END();
- /* multi/exec */
- if(ra->z_multi_exec) {
+ /* multi/exec */
+ if(ra->z_multi_exec) {
call_user_function(&redis_ce->function_table, ra->z_multi_exec, &z_fun, return_value, argc, z_callargs);
zval_dtor(return_value);
zval_dtor(&z_fun);
for (i = 0; i < argc; ++i) {
zval_dtor(&z_callargs[i]);
}
- efree(z_callargs);
- RETURN_ZVAL(getThis(), 1, 0);
- }
+ efree(z_callargs);
+ RETURN_ZVAL(getThis(), 1, 0);
+ }
/* check if write cmd */
b_write_cmd = ra_is_write_cmd(ra, cmd, cmd_len);
- /* CALL! */
- if(ra->index && b_write_cmd) {
+ /* CALL! */
+ if(ra->index && b_write_cmd) {
/* add MULTI + SADD */
ra_index_multi(redis_inst, MULTI TSRMLS_CC);
- /* call using discarded temp value and extract exec results after. */
+ /* call using discarded temp value and extract exec results after. */
call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
zval_dtor(return_value);
- /* add keys to index. */
- ra_index_key(key, key_len, redis_inst TSRMLS_CC);
+ /* add keys to index. */
+ ra_index_key(key, key_len, redis_inst TSRMLS_CC);
- /* call EXEC */
- ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
- } else { /* call directly through. */
- call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
+ /* call EXEC */
+ ra_index_exec(redis_inst, return_value, 0 TSRMLS_CC);
+ } else { /* call directly through. */
+ call_user_function(&redis_ce->function_table, redis_inst, &z_fun, return_value, argc, z_callargs);
if (!b_write_cmd) {
/* check if we have an error. */
@@ -467,122 +467,122 @@ ra_forward_call(INTERNAL_FUNCTION_PARAMETERS, RedisArray *ra, const char *cmd, i
ra_move_key(key, key_len, redis_inst, z_new_target TSRMLS_CC);
}
}
- }
+ }
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_fun);
for (i = 0; i < argc; ++i) {
zval_dtor(&z_callargs[i]);
}
- efree(z_callargs);
+ efree(z_callargs);
}
PHP_METHOD(RedisArray, __call)
{
- zval *object;
- RedisArray *ra;
- zval *z_args;
+ zval *object;
+ RedisArray *ra;
+ zval *z_args;
- char *cmd;
- strlen_t cmd_len;
+ char *cmd;
+ strlen_t cmd_len;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa",
- &object, redis_array_ce, &cmd, &cmd_len, &z_args) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Osa",
+ &object, redis_array_ce, &cmd, &cmd_len, &z_args) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
- ra_forward_call(INTERNAL_FUNCTION_PARAM_PASSTHRU, ra, cmd, cmd_len, z_args, NULL);
+ ra_forward_call(INTERNAL_FUNCTION_PARAM_PASSTHRU, ra, cmd, cmd_len, z_args, NULL);
}
PHP_METHOD(RedisArray, _hosts)
{
- zval *object;
- int i;
- RedisArray *ra;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
-
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
-
- array_init(return_value);
- for(i = 0; i < ra->count; ++i) {
- add_next_index_string(return_value, ra->hosts[i]);
- }
+ zval *object;
+ int i;
+ RedisArray *ra;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ array_init(return_value);
+ for(i = 0; i < ra->count; ++i) {
+ add_next_index_string(return_value, ra->hosts[i]);
+ }
}
PHP_METHOD(RedisArray, _target)
{
- zval *object;
- RedisArray *ra;
- char *key;
- strlen_t key_len;
- zval *redis_inst;
+ zval *object;
+ RedisArray *ra;
+ char *key;
+ strlen_t key_len;
+ zval *redis_inst;
int i;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
- &object, redis_array_ce, &key, &key_len) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
+ &object, redis_array_ce, &key, &key_len) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
- redis_inst = ra_find_node(ra, key, key_len, &i TSRMLS_CC);
- if(redis_inst) {
+ redis_inst = ra_find_node(ra, key, key_len, &i TSRMLS_CC);
+ if(redis_inst) {
RETURN_STRING(ra->hosts[i]);
- } else {
- RETURN_NULL();
- }
+ } else {
+ RETURN_NULL();
+ }
}
PHP_METHOD(RedisArray, _instance)
{
- zval *object;
- RedisArray *ra;
- char *target;
- strlen_t target_len;
- zval *z_redis;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
- &object, redis_array_ce, &target, &target_len) == FAILURE) {
- RETURN_FALSE;
- }
-
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
-
- z_redis = ra_find_node_by_name(ra, target, target_len TSRMLS_CC);
- if(z_redis) {
- RETURN_ZVAL(z_redis, 1, 0);
- } else {
- RETURN_NULL();
- }
+ zval *object;
+ RedisArray *ra;
+ char *target;
+ strlen_t target_len;
+ zval *z_redis;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
+ &object, redis_array_ce, &target, &target_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ z_redis = ra_find_node_by_name(ra, target, target_len TSRMLS_CC);
+ if(z_redis) {
+ RETURN_ZVAL(z_redis, 1, 0);
+ } else {
+ RETURN_NULL();
+ }
}
PHP_METHOD(RedisArray, _function)
{
- zval *object, *z_fun;
- RedisArray *ra;
+ zval *object, *z_fun;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
z_fun = &ra->z_fun;
RETURN_ZVAL(z_fun, 1, 0);
@@ -590,17 +590,17 @@ PHP_METHOD(RedisArray, _function)
PHP_METHOD(RedisArray, _distributor)
{
- zval *object, *z_dist;
- RedisArray *ra;
+ zval *object, *z_dist;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
z_dist = &ra->z_dist;
RETURN_ZVAL(z_dist, 1, 0);
@@ -608,81 +608,81 @@ PHP_METHOD(RedisArray, _distributor)
PHP_METHOD(RedisArray, _rehash)
{
- zval *object;
- RedisArray *ra;
- zend_fcall_info z_cb = {0};
- zend_fcall_info_cache z_cb_cache = {0};
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|f",
- &object, redis_array_ce, &z_cb, &z_cb_cache) == FAILURE) {
- RETURN_FALSE;
- }
-
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
-
- if (ZEND_NUM_ARGS() == 0) {
- ra_rehash(ra, NULL, NULL TSRMLS_CC);
- } else {
- ra_rehash(ra, &z_cb, &z_cb_cache TSRMLS_CC);
- }
+ zval *object;
+ RedisArray *ra;
+ zend_fcall_info z_cb = {0};
+ zend_fcall_info_cache z_cb_cache = {0};
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|f",
+ &object, redis_array_ce, &z_cb, &z_cb_cache) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ if (ZEND_NUM_ARGS() == 0) {
+ ra_rehash(ra, NULL, NULL TSRMLS_CC);
+ } else {
+ ra_rehash(ra, &z_cb, &z_cb_cache TSRMLS_CC);
+ }
}
static void multihost_distribute(INTERNAL_FUNCTION_PARAMETERS, const char *method_name)
{
- zval *object, z_fun;
- int i;
- RedisArray *ra;
+ zval *object, z_fun;
+ int i;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
- /* prepare call */
- ZVAL_STRING(&z_fun, method_name);
+ /* prepare call */
+ ZVAL_STRING(&z_fun, method_name);
- array_init(return_value);
- for(i = 0; i < ra->count; ++i) {
+ array_init(return_value);
+ for(i = 0; i < ra->count; ++i) {
zval zv, *z_tmp = &zv;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#endif
- /* Call each node in turn */
+ /* Call each node in turn */
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_fun, z_tmp, 0, NULL);
- add_assoc_zval(return_value, ra->hosts[i], z_tmp);
- }
+ add_assoc_zval(return_value, ra->hosts[i], z_tmp);
+ }
zval_dtor(&z_fun);
}
PHP_METHOD(RedisArray, info)
{
- multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "INFO");
+ multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "INFO");
}
PHP_METHOD(RedisArray, ping)
{
- multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PING");
+ multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "PING");
}
PHP_METHOD(RedisArray, flushdb)
{
- multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHDB");
+ multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHDB");
}
PHP_METHOD(RedisArray, flushall)
{
- multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHALL");
+ multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "FLUSHALL");
}
-PHP_METHOD(RedisArray, save)
+PHP_METHOD(RedisArray, save)
{
multihost_distribute(INTERNAL_FUNCTION_PARAM_PASSTHRU, "SAVE");
}
@@ -695,125 +695,125 @@ PHP_METHOD(RedisArray, bgsave)
PHP_METHOD(RedisArray, keys)
{
- zval *object, z_args[1], z_fun;
- RedisArray *ra;
- char *pattern;
- strlen_t pattern_len;
+ zval *object, z_args[1], z_fun;
+ RedisArray *ra;
+ char *pattern;
+ strlen_t pattern_len;
int i;
- /* Make sure the prototype is correct */
- if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
- &object, redis_array_ce, &pattern, &pattern_len) == FAILURE)
- {
- RETURN_FALSE;
- }
+ /* Make sure the prototype is correct */
+ if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os",
+ &object, redis_array_ce, &pattern, &pattern_len) == FAILURE)
+ {
+ RETURN_FALSE;
+ }
- /* Make sure we can grab our RedisArray object */
+ /* Make sure we can grab our RedisArray object */
if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ RETURN_FALSE;
+ }
- /* Set up our function call (KEYS) */
- ZVAL_STRINGL(&z_fun, "KEYS", 4);
+ /* Set up our function call (KEYS) */
+ ZVAL_STRINGL(&z_fun, "KEYS", 4);
- /* We will be passing with one string argument (the pattern) */
- ZVAL_STRINGL(z_args, pattern, pattern_len);
+ /* We will be passing with one string argument (the pattern) */
+ ZVAL_STRINGL(z_args, pattern, pattern_len);
- /* Init our array return */
- array_init(return_value);
+ /* Init our array return */
+ array_init(return_value);
- /* Iterate our RedisArray nodes */
- for(i=0; i<ra->count; ++i) {
+ /* Iterate our RedisArray nodes */
+ for(i=0; i<ra->count; ++i) {
zval zv, *z_tmp = &zv;
#if (PHP_MAJOR_VERSION < 7)
- /* Return for this node */
- MAKE_STD_ZVAL(z_tmp);
+ /* Return for this node */
+ MAKE_STD_ZVAL(z_tmp);
#endif
- /* Call KEYS on each node */
+ /* Call KEYS on each node */
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_fun, z_tmp, 1, z_args);
- /* Add the result for this host */
- add_assoc_zval(return_value, ra->hosts[i], z_tmp);
- }
+ /* Add the result for this host */
+ add_assoc_zval(return_value, ra->hosts[i], z_tmp);
+ }
zval_dtor(&z_args[0]);
zval_dtor(&z_fun);
}
PHP_METHOD(RedisArray, getOption)
{
- zval *object, z_fun, z_args[1];
- int i;
- RedisArray *ra;
- zend_long opt;
+ zval *object, z_fun, z_args[1];
+ int i;
+ RedisArray *ra;
+ zend_long opt;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
- &object, redis_array_ce, &opt) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
+ &object, redis_array_ce, &opt) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
- /* prepare call */
- ZVAL_STRINGL(&z_fun, "getOption", 9);
+ /* prepare call */
+ ZVAL_STRINGL(&z_fun, "getOption", 9);
- /* copy arg */
- ZVAL_LONG(&z_args[0], opt);
+ /* copy arg */
+ ZVAL_LONG(&z_args[0], opt);
- array_init(return_value);
- for(i = 0; i < ra->count; ++i) {
+ array_init(return_value);
+ for(i = 0; i < ra->count; ++i) {
zval zv, *z_tmp = &zv;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#endif
- /* Call each node in turn */
+ /* Call each node in turn */
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_fun, z_tmp, 1, z_args);
- add_assoc_zval(return_value, ra->hosts[i], z_tmp);
- }
+ add_assoc_zval(return_value, ra->hosts[i], z_tmp);
+ }
zval_dtor(&z_fun);
}
PHP_METHOD(RedisArray, setOption)
{
- zval *object, z_fun, z_args[2];
- int i;
- RedisArray *ra;
- zend_long opt;
- char *val_str;
- strlen_t val_len;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
- &object, redis_array_ce, &opt, &val_str, &val_len) == FAILURE) {
- RETURN_FALSE;
- }
-
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
-
- /* prepare call */
- ZVAL_STRINGL(&z_fun, "setOption", 9);
-
- /* copy args */
- ZVAL_LONG(&z_args[0], opt);
- ZVAL_STRINGL(&z_args[1], val_str, val_len);
-
- array_init(return_value);
- for(i = 0; i < ra->count; ++i) {
+ zval *object, z_fun, z_args[2];
+ int i;
+ RedisArray *ra;
+ zend_long opt;
+ char *val_str;
+ strlen_t val_len;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ols",
+ &object, redis_array_ce, &opt, &val_str, &val_len) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ /* prepare call */
+ ZVAL_STRINGL(&z_fun, "setOption", 9);
+
+ /* copy args */
+ ZVAL_LONG(&z_args[0], opt);
+ ZVAL_STRINGL(&z_args[1], val_str, val_len);
+
+ array_init(return_value);
+ for(i = 0; i < ra->count; ++i) {
zval zv, *z_tmp = &zv;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#endif
- /* Call each node in turn */
+ /* Call each node in turn */
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_fun, z_tmp, 2, z_args);
- add_assoc_zval(return_value, ra->hosts[i], z_tmp);
- }
+ add_assoc_zval(return_value, ra->hosts[i], z_tmp);
+ }
zval_dtor(&z_args[1]);
zval_dtor(&z_fun);
}
@@ -821,65 +821,65 @@ PHP_METHOD(RedisArray, setOption)
PHP_METHOD(RedisArray, select)
{
zval *object, z_fun, z_args[1];
- int i;
- RedisArray *ra;
- zend_long opt;
+ int i;
+ RedisArray *ra;
+ zend_long opt;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
- &object, redis_array_ce, &opt) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Ol",
+ &object, redis_array_ce, &opt) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
- /* prepare call */
- ZVAL_STRINGL(&z_fun, "select", 6);
+ /* prepare call */
+ ZVAL_STRINGL(&z_fun, "select", 6);
- /* copy args */
+ /* copy args */
ZVAL_LONG(&z_args[0], opt);
- array_init(return_value);
- for(i = 0; i < ra->count; ++i) {
+ array_init(return_value);
+ for(i = 0; i < ra->count; ++i) {
zval zv, *z_tmp = &zv;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#endif
- /* Call each node in turn */
+ /* Call each node in turn */
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_fun, z_tmp, 1, z_args);
- add_assoc_zval(return_value, ra->hosts[i], z_tmp);
- }
+ add_assoc_zval(return_value, ra->hosts[i], z_tmp);
+ }
zval_dtor(&z_fun);
}
#if (PHP_MAJOR_VERSION < 7)
#define HANDLE_MULTI_EXEC(ra, cmd) do { \
if (ra && ra->z_multi_exec) { \
- int i, num_varargs;\
- zval ***varargs = NULL, *z_arg_array; \
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O*",\
- &object, redis_array_ce, &varargs, &num_varargs) == FAILURE) {\
- RETURN_FALSE;\
- }\
- /* copy all args into a zval hash table */\
+ int i, num_varargs;\
+ zval ***varargs = NULL, *z_arg_array; \
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O*",\
+ &object, redis_array_ce, &varargs, &num_varargs) == FAILURE) {\
+ RETURN_FALSE;\
+ }\
+ /* copy all args into a zval hash table */\
MAKE_STD_ZVAL(z_arg_array); \
- array_init(z_arg_array);\
- for(i = 0; i < num_varargs; ++i) {\
- zval *z_tmp;\
+ array_init(z_arg_array);\
+ for(i = 0; i < num_varargs; ++i) {\
+ zval *z_tmp;\
MAKE_STD_ZVAL(z_tmp); \
ZVAL_ZVAL(z_tmp, *varargs[i], 1, 0); \
add_next_index_zval(z_arg_array, z_tmp); \
- }\
- /* call */\
+ }\
+ /* call */\
ra_forward_call(INTERNAL_FUNCTION_PARAM_PASSTHRU, ra, cmd, sizeof(cmd) - 1, z_arg_array, NULL); \
zval_ptr_dtor(&z_arg_array); \
- if(varargs) {\
- efree(varargs);\
- }\
- return;\
- }\
+ if(varargs) {\
+ efree(varargs);\
+ }\
+ return;\
+ }\
}while(0)
#else
#define HANDLE_MULTI_EXEC(ra, cmd) do { \
@@ -908,109 +908,109 @@ PHP_METHOD(RedisArray, select)
/* MGET will distribute the call to several nodes and regroup the values. */
PHP_METHOD(RedisArray, mget)
{
- zval *object, *z_keys, z_argarray, *data, z_ret, *z_cur, z_tmp_array, *z_tmp;
- int i, j, n;
- RedisArray *ra;
- int *pos, argc, *argc_each;
- HashTable *h_keys;
- zval **argv;
+ zval *object, *z_keys, z_argarray, *data, z_ret, *z_cur, z_tmp_array, *z_tmp;
+ int i, j, n;
+ RedisArray *ra;
+ int *pos, argc, *argc_each;
+ HashTable *h_keys;
+ zval **argv;
if ((ra = redis_array_get(getThis() TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
- /* Multi/exec support */
+ /* Multi/exec support */
HANDLE_MULTI_EXEC(ra, "MGET");
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
- &object, redis_array_ce, &z_keys) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oa",
+ &object, redis_array_ce, &z_keys) == FAILURE) {
+ RETURN_FALSE;
+ }
- /* init data structures */
- h_keys = Z_ARRVAL_P(z_keys);
+ /* init data structures */
+ h_keys = Z_ARRVAL_P(z_keys);
if ((argc = zend_hash_num_elements(h_keys)) == 0) {
RETURN_FALSE;
}
- argv = emalloc(argc * sizeof(zval*));
- pos = emalloc(argc * sizeof(int));
+ argv = emalloc(argc * sizeof(zval*));
+ pos = emalloc(argc * sizeof(int));
- argc_each = emalloc(ra->count * sizeof(int));
- memset(argc_each, 0, ra->count * sizeof(int));
+ argc_each = emalloc(ra->count * sizeof(int));
+ memset(argc_each, 0, ra->count * sizeof(int));
- /* associate each key to a redis node */
+ /* associate each key to a redis node */
i = 0;
ZEND_HASH_FOREACH_VAL(h_keys, data) {
- /* If we need to represent a long key as a string */
- unsigned int key_len;
- char kbuf[40], *key_lookup;
-
- /* phpredis proper can only use string or long keys, so restrict to that here */
- if (Z_TYPE_P(data) != IS_STRING && Z_TYPE_P(data) != IS_LONG) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "MGET: all keys must be strings or longs");
- efree(argv);
- efree(pos);
- efree(argc_each);
- RETURN_FALSE;
- }
-
- /* Convert to a string for hash lookup if it isn't one */
- if (Z_TYPE_P(data) == IS_STRING) {
- key_len = Z_STRLEN_P(data);
+ /* If we need to represent a long key as a string */
+ unsigned int key_len;
+ char kbuf[40], *key_lookup;
+
+ /* phpredis proper can only use string or long keys, so restrict to that here */
+ if (Z_TYPE_P(data) != IS_STRING && Z_TYPE_P(data) != IS_LONG) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "MGET: all keys must be strings or longs");
+ efree(argv);
+ efree(pos);
+ efree(argc_each);
+ RETURN_FALSE;
+ }
+
+ /* Convert to a string for hash lookup if it isn't one */
+ if (Z_TYPE_P(data) == IS_STRING) {
+ key_len = Z_STRLEN_P(data);
key_lookup = Z_STRVAL_P(data);
- } else {
- key_len = snprintf(kbuf, sizeof(kbuf), "%ld", Z_LVAL_P(data));
- key_lookup = (char*)kbuf;
- }
+ } else {
+ key_len = snprintf(kbuf, sizeof(kbuf), "%ld", Z_LVAL_P(data));
+ key_lookup = (char*)kbuf;
+ }
- /* Find our node */
+ /* Find our node */
if (ra_find_node(ra, key_lookup, key_len, &pos[i] TSRMLS_CC) == NULL) {
/* TODO: handle */
}
- argc_each[pos[i]]++; /* count number of keys per node */
- argv[i++] = data;
- } ZEND_HASH_FOREACH_END();
+ argc_each[pos[i]]++; /* count number of keys per node */
+ argv[i++] = data;
+ } ZEND_HASH_FOREACH_END();
- array_init(&z_tmp_array);
- /* calls */
- for(n = 0; n < ra->count; ++n) { /* for each node */
- /* We don't even need to make a call to this node if no keys go there */
- if(!argc_each[n]) continue;
+ array_init(&z_tmp_array);
+ /* calls */
+ for(n = 0; n < ra->count; ++n) { /* for each node */
+ /* We don't even need to make a call to this node if no keys go there */
+ if(!argc_each[n]) continue;
- /* copy args for MGET call on node. */
- array_init(&z_argarray);
+ /* copy args for MGET call on node. */
+ array_init(&z_argarray);
- for(i = 0; i < argc; ++i) {
- if(pos[i] != n) continue;
+ for(i = 0; i < argc; ++i) {
+ if(pos[i] != n) continue;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#else
zval zv;
z_tmp = &zv;
#endif
ZVAL_ZVAL(z_tmp, argv[i], 1, 0);
- add_next_index_zval(&z_argarray, z_tmp);
- }
+ add_next_index_zval(&z_argarray, z_tmp);
+ }
zval z_fun;
/* prepare call */
ZVAL_STRINGL(&z_fun, "MGET", 4);
- /* call MGET on the node */
+ /* call MGET on the node */
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
zval_dtor(&z_fun);
- /* cleanup args array */
- zval_dtor(&z_argarray);
+ /* cleanup args array */
+ zval_dtor(&z_argarray);
/* Error out if we didn't get a proper response */
if (Z_TYPE(z_ret) != IS_ARRAY) {
/* cleanup */
zval_dtor(&z_ret);
zval_dtor(&z_tmp_array);
- efree(argv);
+ efree(argv);
efree(pos);
efree(argc_each);
@@ -1018,41 +1018,41 @@ PHP_METHOD(RedisArray, mget)
RETURN_FALSE;
}
- for(i = 0, j = 0; i < argc; ++i) {
+ for(i = 0, j = 0; i < argc; ++i) {
if (pos[i] != n || (z_cur = zend_hash_index_find(Z_ARRVAL(z_ret), j++)) == NULL) continue;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#else
zval zv;
z_tmp = &zv;
#endif
ZVAL_ZVAL(z_tmp, z_cur, 1, 0);
- add_index_zval(&z_tmp_array, i, z_tmp);
- }
- zval_dtor(&z_ret);
- }
-
- array_init(return_value);
- /* copy temp array in the right order to return_value */
- for(i = 0; i < argc; ++i) {
+ add_index_zval(&z_tmp_array, i, z_tmp);
+ }
+ zval_dtor(&z_ret);
+ }
+
+ array_init(return_value);
+ /* copy temp array in the right order to return_value */
+ for(i = 0; i < argc; ++i) {
if ((z_cur = zend_hash_index_find(Z_ARRVAL(z_tmp_array), i)) == NULL) continue;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#else
zval zv;
z_tmp = &zv;
#endif
ZVAL_ZVAL(z_tmp, z_cur, 1, 0);
- add_next_index_zval(return_value, z_tmp);
- }
-
- /* cleanup */
- zval_dtor(&z_tmp_array);
- efree(argv);
- efree(pos);
- efree(argc_each);
+ add_next_index_zval(return_value, z_tmp);
+ }
+
+ /* cleanup */
+ zval_dtor(&z_tmp_array);
+ efree(argv);
+ efree(pos);
+ efree(argc_each);
}
@@ -1110,7 +1110,7 @@ PHP_METHOD(RedisArray, mset)
// TODO: handle
}
- argc_each[pos[i]]++; /* count number of keys per node */
+ argc_each[pos[i]]++; /* count number of keys per node */
keys[i] = estrndup(key, key_len);
key_lens[i] = (int)key_len;
argv[i] = data;
@@ -1188,240 +1188,240 @@ PHP_METHOD(RedisArray, mset)
/* DEL will distribute the call to several nodes and regroup the values. */
PHP_METHOD(RedisArray, del)
{
- zval *object, z_keys, z_fun, *data, z_ret, *z_tmp, *z_args;
- int i, n;
- RedisArray *ra;
- int *pos, argc = ZEND_NUM_ARGS(), *argc_each;
- HashTable *h_keys;
- zval **argv;
- long total = 0;
- int free_zkeys = 0;
+ zval *object, z_keys, z_fun, *data, z_ret, *z_tmp, *z_args;
+ int i, n;
+ RedisArray *ra;
+ int *pos, argc = ZEND_NUM_ARGS(), *argc_each;
+ HashTable *h_keys;
+ zval **argv;
+ long total = 0;
+ int free_zkeys = 0;
if ((ra = redis_array_get(getThis() TSRMLS_CC)) == NULL) {
RETURN_FALSE;
}
- /* Multi/exec support */
+ /* Multi/exec support */
HANDLE_MULTI_EXEC(ra, "DEL");
- /* get all args in z_args */
- z_args = emalloc(argc * sizeof(zval));
- if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
- efree(z_args);
- RETURN_FALSE;
- }
-
- /* if single array arg, point z_keys to it. */
- if (argc == 1 && Z_TYPE(z_args[0]) == IS_ARRAY) {
- z_keys = z_args[0];
- } else {
- /* copy all elements to z_keys */
- array_init(&z_keys);
- for (i = 0; i < argc; ++i) {
+ /* get all args in z_args */
+ z_args = emalloc(argc * sizeof(zval));
+ if (zend_get_parameters_array(ht, argc, z_args) == FAILURE) {
+ efree(z_args);
+ RETURN_FALSE;
+ }
+
+ /* if single array arg, point z_keys to it. */
+ if (argc == 1 && Z_TYPE(z_args[0]) == IS_ARRAY) {
+ z_keys = z_args[0];
+ } else {
+ /* copy all elements to z_keys */
+ array_init(&z_keys);
+ for (i = 0; i < argc; ++i) {
zval *z_arg = &z_args[i];
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#else
zval zv;
z_tmp = &zv;
#endif
ZVAL_ZVAL(z_tmp, z_arg, 1, 0);
- /* add copy to z_keys */
- add_next_index_zval(&z_keys, z_tmp);
- }
- free_zkeys = 1;
- }
-
- /* init data structures */
- h_keys = Z_ARRVAL(z_keys);
+ /* add copy to z_keys */
+ add_next_index_zval(&z_keys, z_tmp);
+ }
+ free_zkeys = 1;
+ }
+
+ /* init data structures */
+ h_keys = Z_ARRVAL(z_keys);
if ((argc = zend_hash_num_elements(h_keys)) == 0) {
if (free_zkeys) zval_dtor(&z_keys);
efree(z_args);
RETURN_FALSE;
}
- argv = emalloc(argc * sizeof(zval*));
- pos = emalloc(argc * sizeof(int));
+ argv = emalloc(argc * sizeof(zval*));
+ pos = emalloc(argc * sizeof(int));
- argc_each = emalloc(ra->count * sizeof(int));
- memset(argc_each, 0, ra->count * sizeof(int));
+ argc_each = emalloc(ra->count * sizeof(int));
+ memset(argc_each, 0, ra->count * sizeof(int));
- /* associate each key to a redis node */
+ /* associate each key to a redis node */
i = 0;
ZEND_HASH_FOREACH_VAL(h_keys, data) {
- if (Z_TYPE_P(data) != IS_STRING) {
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "DEL: all keys must be string.");
+ if (Z_TYPE_P(data) != IS_STRING) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "DEL: all keys must be string.");
if (free_zkeys) zval_dtor(&z_keys);
efree(z_args);
efree(argv);
- efree(pos);
- efree(argc_each);
- RETURN_FALSE;
- }
+ efree(pos);
+ efree(argc_each);
+ RETURN_FALSE;
+ }
if (ra_find_node(ra, Z_STRVAL_P(data), Z_STRLEN_P(data), &pos[i] TSRMLS_CC) == NULL) {
// TODO: handle
}
- argc_each[pos[i]]++; /* count number of keys per node */
- argv[i++] = data;
- } ZEND_HASH_FOREACH_END();
+ argc_each[pos[i]]++; /* count number of keys per node */
+ argv[i++] = data;
+ } ZEND_HASH_FOREACH_END();
- /* prepare call */
- ZVAL_STRINGL(&z_fun, "DEL", 3);
+ /* prepare call */
+ ZVAL_STRINGL(&z_fun, "DEL", 3);
- /* calls */
- for(n = 0; n < ra->count; ++n) { /* for each node */
- /* We don't even need to make a call to this node if no keys go there */
- if(!argc_each[n]) continue;
+ /* calls */
+ for(n = 0; n < ra->count; ++n) { /* for each node */
+ /* We don't even need to make a call to this node if no keys go there */
+ if(!argc_each[n]) continue;
- int found = 0;
+ int found = 0;
zval z_argarray;
- /* copy args */
- array_init(&z_argarray);
- for(i = 0; i < argc; ++i) {
- if(pos[i] != n) continue;
+ /* copy args */
+ array_init(&z_argarray);
+ for(i = 0; i < argc; ++i) {
+ if(pos[i] != n) continue;
#if (PHP_MAJOR_VERSION < 7)
- MAKE_STD_ZVAL(z_tmp);
+ MAKE_STD_ZVAL(z_tmp);
#else
zval zv;
z_tmp = &zv;
#endif
ZVAL_ZVAL(z_tmp, argv[i], 1, 0);
- add_next_index_zval(&z_argarray, z_tmp);
- found++;
- }
+ add_next_index_zval(&z_argarray, z_tmp);
+ found++;
+ }
- if(!found) { /* don't run empty DELs */
- zval_dtor(&z_argarray);
- continue;
- }
+ if(!found) { /* don't run empty DELs */
+ zval_dtor(&z_argarray);
+ continue;
+ }
- if(ra->index) { /* add MULTI */
- ra_index_multi(&ra->redis[n], MULTI TSRMLS_CC);
- }
+ if(ra->index) { /* add MULTI */
+ ra_index_multi(&ra->redis[n], MULTI TSRMLS_CC);
+ }
- /* call */
+ /* call */
call_user_function(&redis_ce->function_table, &ra->redis[n], &z_fun, &z_ret, 1, &z_argarray);
- if(ra->index) {
+ if(ra->index) {
zval_dtor(&z_ret);
- ra_index_del(&z_argarray, &ra->redis[n] TSRMLS_CC); /* use SREM to remove keys from node index */
- ra_index_exec(&ra->redis[n], &z_ret, 0 TSRMLS_CC); /* run EXEC */
- }
- total += Z_LVAL(z_ret); /* increment total */
-
- zval_dtor(&z_argarray);
- zval_dtor(&z_ret);
- }
-
- /* cleanup */
- zval_dtor(&z_fun);
- efree(argv);
- efree(pos);
- efree(argc_each);
-
- if(free_zkeys) {
- zval_dtor(&z_keys);
- }
-
- efree(z_args);
- RETURN_LONG(total);
+ ra_index_del(&z_argarray, &ra->redis[n] TSRMLS_CC); /* use SREM to remove keys from node index */
+ ra_index_exec(&ra->redis[n], &z_ret, 0 TSRMLS_CC); /* run EXEC */
+ }
+ total += Z_LVAL(z_ret); /* increment total */
+
+ zval_dtor(&z_argarray);
+ zval_dtor(&z_ret);
+ }
+
+ /* cleanup */
+ zval_dtor(&z_fun);
+ efree(argv);
+ efree(pos);
+ efree(argc_each);
+
+ if(free_zkeys) {
+ zval_dtor(&z_keys);
+ }
+
+ efree(z_args);
+ RETURN_LONG(total);
}
PHP_METHOD(RedisArray, multi)
{
- zval *object;
- RedisArray *ra;
- zval *z_redis;
- char *host;
- strlen_t host_len;
- zend_long multi_value = MULTI;
-
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l",
- &object, redis_array_ce, &host, &host_len, &multi_value) == FAILURE) {
- RETURN_FALSE;
- }
-
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
- RETURN_FALSE;
- }
-
- /* find node */
- z_redis = ra_find_node_by_name(ra, host, host_len TSRMLS_CC);
- if(!z_redis) {
- RETURN_FALSE;
- }
-
- if(multi_value != MULTI && multi_value != PIPELINE) {
- RETURN_FALSE;
- }
-
- /* save multi object */
- ra->z_multi_exec = z_redis;
-
- /* switch redis instance to multi/exec mode. */
- ra_index_multi(z_redis, multi_value TSRMLS_CC);
-
- /* return this. */
- RETURN_ZVAL(object, 1, 0);
+ zval *object;
+ RedisArray *ra;
+ zval *z_redis;
+ char *host;
+ strlen_t host_len;
+ zend_long multi_value = MULTI;
+
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Os|l",
+ &object, redis_array_ce, &host, &host_len, &multi_value) == FAILURE) {
+ RETURN_FALSE;
+ }
+
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL) {
+ RETURN_FALSE;
+ }
+
+ /* find node */
+ z_redis = ra_find_node_by_name(ra, host, host_len TSRMLS_CC);
+ if(!z_redis) {
+ RETURN_FALSE;
+ }
+
+ if(multi_value != MULTI && multi_value != PIPELINE) {
+ RETURN_FALSE;
+ }
+
+ /* save multi object */
+ ra->z_multi_exec = z_redis;
+
+ /* switch redis instance to multi/exec mode. */
+ ra_index_multi(z_redis, multi_value TSRMLS_CC);
+
+ /* return this. */
+ RETURN_ZVAL(object, 1, 0);
}
PHP_METHOD(RedisArray, exec)
{
- zval *object;
- RedisArray *ra;
+ zval *object;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
+ RETURN_FALSE;
+ }
- /* switch redis instance out of multi/exec mode. */
- ra_index_exec(ra->z_multi_exec, return_value, 1 TSRMLS_CC);
+ /* switch redis instance out of multi/exec mode. */
+ ra_index_exec(ra->z_multi_exec, return_value, 1 TSRMLS_CC);
- /* remove multi object */
- ra->z_multi_exec = NULL;
+ /* remove multi object */
+ ra->z_multi_exec = NULL;
}
PHP_METHOD(RedisArray, discard)
{
- zval *object;
- RedisArray *ra;
+ zval *object;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
+ RETURN_FALSE;
+ }
- /* switch redis instance out of multi/exec mode. */
- ra_index_discard(ra->z_multi_exec, return_value TSRMLS_CC);
+ /* switch redis instance out of multi/exec mode. */
+ ra_index_discard(ra->z_multi_exec, return_value TSRMLS_CC);
- /* remove multi object */
- ra->z_multi_exec = NULL;
+ /* remove multi object */
+ ra->z_multi_exec = NULL;
}
PHP_METHOD(RedisArray, unwatch)
{
- zval *object;
- RedisArray *ra;
+ zval *object;
+ RedisArray *ra;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
- &object, redis_array_ce) == FAILURE) {
- RETURN_FALSE;
- }
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O",
+ &object, redis_array_ce) == FAILURE) {
+ RETURN_FALSE;
+ }
- if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
- RETURN_FALSE;
- }
+ if ((ra = redis_array_get(object TSRMLS_CC)) == NULL || !ra->z_multi_exec) {
+ RETURN_FALSE;
+ }
- /* unwatch keys, stay in multi/exec mode. */
- ra_index_unwatch(ra->z_multi_exec, return_value TSRMLS_CC);
+ /* unwatch keys, stay in multi/exec mode. */
+ ra_index_unwatch(ra->z_multi_exec, return_value TSRMLS_CC);
}
diff --git a/redis_array.h b/redis_array.h
index f036c264..d6a00fa0 100644
--- a/redis_array.h
+++ b/redis_array.h
@@ -39,20 +39,20 @@ PHP_METHOD(RedisArray, unwatch);
typedef struct RedisArray_ {
- int count;
- char **hosts; /* array of host:port strings */
- zval *redis; /* array of Redis instances */
- zval *z_multi_exec; /* Redis instance to be used in multi-exec */
- zend_bool index; /* use per-node index */
- zend_bool auto_rehash; /* migrate keys on read operations */
- zend_bool pconnect; /* should we use pconnect */
- zval z_fun; /* key extractor, callable */
- zval z_dist; /* key distributor, callable */
- HashTable *pure_cmds; /* hash table */
- double connect_timeout; /* socket connect timeout */
- double read_timeout; /* socket read timeout */
+ int count;
+ char **hosts; /* array of host:port strings */
+ zval *redis; /* array of Redis instances */
+ zval *z_multi_exec; /* Redis instance to be used in multi-exec */
+ zend_bool index; /* use per-node index */
+ zend_bool auto_rehash; /* migrate keys on read operations */
+ zend_bool pconnect; /* should we use pconnect */
+ zval z_fun; /* key extractor, callable */
+ zval z_dist; /* key distributor, callable */
+ HashTable *pure_cmds; /* hash table */
+ double connect_timeout; /* socket connect timeout */
+ double read_timeout; /* socket read timeout */
- struct RedisArray_ *prev;
+ struct RedisArray_ *prev;
} RedisArray;
#if (PHP_MAJOR_VERSION < 7)
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 0d740a0f..ebbaef5b 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -25,43 +25,43 @@
#include "ext/standard/url.h"
#include "ext/standard/crc32.h"
-#define PHPREDIS_INDEX_NAME "__phpredis_array_index__"
+#define PHPREDIS_INDEX_NAME "__phpredis_array_index__"
extern zend_class_entry *redis_ce;
RedisArray*
ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b_lazy_connect TSRMLS_DC)
{
- int i = 0, host_len;
- char *host, *p;
- short port;
- zval *zpData, z_cons, z_ret;
+ int i = 0, host_len;
+ char *host, *p;
+ short port;
+ zval *zpData, z_cons, z_ret;
redis_object *redis;
- /* function calls on the Redis object */
- ZVAL_STRINGL(&z_cons, "__construct", 11);
+ /* function calls on the Redis object */
+ ZVAL_STRINGL(&z_cons, "__construct", 11);
- /* init connections */
+ /* init connections */
ZEND_HASH_FOREACH_VAL(hosts, zpData) {
if (Z_TYPE_P(zpData) != IS_STRING) {
zval_dtor(&z_cons);
return NULL;
}
- /* default values */
- host = Z_STRVAL_P(zpData);
- host_len = Z_STRLEN_P(zpData);
- ra->hosts[i] = estrndup(host, host_len);
- port = 6379;
+ /* default values */
+ host = Z_STRVAL_P(zpData);
+ host_len = Z_STRLEN_P(zpData);
+ ra->hosts[i] = estrndup(host, host_len);
+ port = 6379;
- if((p = strrchr(host, ':'))) { /* found port */
- host_len = p - host;
- port = (short)atoi(p+1);
- } else if(strchr(host,'/') != NULL) { /* unix socket */
+ if((p = strrchr(host, ':'))) { /* found port */
+ host_len = p - host;
+ port = (short)atoi(p+1);
+ } else if(strchr(host,'/') != NULL) { /* unix socket */
port = -1;
}
- /* create Redis object */
+ /* create Redis object */
#if (PHP_MAJOR_VERSION < 7)
INIT_PZVAL(&ra->redis[i]);
#endif
@@ -75,21 +75,21 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts, long retry_interval, zend_bool b
redis = (redis_object *)((char *)Z_OBJ_P(&ra->redis[i]) - XtOffsetOf(redis_object, std));
#endif
- /* create socket */
- redis->sock = redis_sock_create(host, host_len, port, ra->connect_timeout, ra->read_timeout, ra->pconnect, NULL, retry_interval, b_lazy_connect);
+ /* create socket */
+ redis->sock = redis_sock_create(host, host_len, port, ra->connect_timeout, ra->read_timeout, ra->pconnect, NULL, retry_interval, b_lazy_connect);
- if (!b_lazy_connect)
- {
- /* connect */
- redis_sock_server_open(redis->sock TSRMLS_CC);
- }
+ if (!b_lazy_connect)
+ {
+ /* connect */
+ redis_sock_server_open(redis->sock TSRMLS_CC);
+ }
- ra->count = ++i;
- } ZEND_HASH_FOREACH_END();
+ ra->count = ++i;
+ } ZEND_HASH_FOREACH_END();
zval_dtor(&z_cons);
- return ra;
+ return ra;
}
/* List pure functions */
@@ -136,26 +136,26 @@ ra_init_function_table(RedisArray *ra)
static int
ra_find_name(const char *name) {
- const char *ini_names, *p, *next;
- /* php_printf("Loading redis array with name=[%s]\n", name); */
-
- ini_names = INI_STR("redis.arrays.names");
- for(p = ini_names; p;) {
- next = strchr(p, ',');
- if(next) {
- if(strncmp(p, name, next - p) == 0) {
- return 1;
- }
- } else {
- if(strcmp(p, name) == 0) {
- return 1;
- }
- break;
- }
- p = next + 1;
- }
-
- return 0;
+ const char *ini_names, *p, *next;
+ /* php_printf("Loading redis array with name=[%s]\n", name); */
+
+ ini_names = INI_STR("redis.arrays.names");
+ for(p = ini_names; p;) {
+ next = strchr(p, ',');
+ if(next) {
+ if(strncmp(p, name, next - p) == 0) {
+ return 1;
+ }
+ } else {
+ if(strcmp(p, name) == 0) {
+ return 1;
+ }
+ break;
+ }
+ p = next + 1;
+ }
+
+ return 0;
}
/* laod array from INI settings */
@@ -173,86 +173,86 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
zval z_params_connect_timeout;
zval z_params_read_timeout;
zval z_params_lazy_connect;
- RedisArray *ra = NULL;
+ RedisArray *ra = NULL;
- zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
- long l_retry_interval = 0;
- zend_bool b_lazy_connect = 0;
- double d_connect_timeout = 0, read_timeout = 0.0;
- HashTable *hHosts = NULL, *hPrev = NULL;
+ zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
+ long l_retry_interval = 0;
+ zend_bool b_lazy_connect = 0;
+ double d_connect_timeout = 0, read_timeout = 0.0;
+ HashTable *hHosts = NULL, *hPrev = NULL;
size_t name_len = strlen(name);
char *iptr;
- /* find entry */
- if(!ra_find_name(name))
- return ra;
+ /* find entry */
+ if(!ra_find_name(name))
+ return ra;
- /* find hosts */
- array_init(&z_params_hosts);
+ /* find hosts */
+ array_init(&z_params_hosts);
if ((iptr = INI_STR("redis.arrays.hosts")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_hosts TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_hosts), name, name_len)) != NULL) {
- hHosts = Z_ARRVAL_P(z_data);
- }
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_hosts), name, name_len)) != NULL) {
+ hHosts = Z_ARRVAL_P(z_data);
+ }
- /* find previous hosts */
- array_init(&z_params_prev);
+ /* find previous hosts */
+ array_init(&z_params_prev);
if ((iptr = INI_STR("redis.arrays.previous")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_prev TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_prev), name, name_len)) != NULL) {
- hPrev = Z_ARRVAL_P(z_data);
- }
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_prev), name, name_len)) != NULL) {
+ hPrev = Z_ARRVAL_P(z_data);
+ }
- /* find function */
- array_init(&z_params_funs);
+ /* find function */
+ array_init(&z_params_funs);
if ((iptr = INI_STR("redis.arrays.functions")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_funs TSRMLS_CC);
}
ZVAL_NULL(&z_fun);
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_funs), name, name_len)) != NULL) {
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_funs), name, name_len)) != NULL) {
ZVAL_ZVAL(&z_fun, z_data, 1, 0);
- }
+ }
- /* find distributor */
- array_init(&z_params_dist);
+ /* find distributor */
+ array_init(&z_params_dist);
if ((iptr = INI_STR("redis.arrays.distributor")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_dist TSRMLS_CC);
}
ZVAL_NULL(&z_dist);
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_dist), name, name_len)) != NULL) {
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_dist), name, name_len)) != NULL) {
ZVAL_ZVAL(&z_dist, z_data, 1, 0);
- }
+ }
- /* find index option */
- array_init(&z_params_index);
+ /* find index option */
+ array_init(&z_params_index);
if ((iptr = INI_STR("redis.arrays.index")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_index TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_index), name, name_len)) != NULL) {
- if (Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
- b_index = 1;
- }
- }
-
- /* find autorehash option */
- array_init(&z_params_autorehash);
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_index), name, name_len)) != NULL) {
+ if (Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
+ b_index = 1;
+ }
+ }
+
+ /* find autorehash option */
+ array_init(&z_params_autorehash);
if ((iptr = INI_STR("redis.arrays.autorehash")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_autorehash TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_autorehash), name, name_len)) != NULL) {
- if(Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
- b_autorehash = 1;
- }
- }
-
- /* find retry interval option */
- array_init(&z_params_retry_interval);
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_autorehash), name, name_len)) != NULL) {
+ if(Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
+ b_autorehash = 1;
+ }
+ }
+
+ /* find retry interval option */
+ array_init(&z_params_retry_interval);
if ((iptr = INI_STR("redis.arrays.retryinterval")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_retry_interval TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_retry_interval), name, name_len)) != NULL) {
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_retry_interval), name, name_len)) != NULL) {
if (Z_TYPE_P(z_data) == IS_LONG) {
l_retry_interval = Z_LVAL_P(z_data);
} else if (Z_TYPE_P(z_data) == IS_STRING) {
@@ -260,7 +260,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
}
}
- /* find pconnect option */
+ /* find pconnect option */
array_init(&z_params_pconnect);
if ((iptr = INI_STR("redis.arrays.pconnect")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_pconnect TSRMLS_CC);
@@ -270,20 +270,20 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
b_pconnect = 1;
}
}
-
+
/* find lazy connect option */
- array_init(&z_params_lazy_connect);
+ array_init(&z_params_lazy_connect);
if ((iptr = INI_STR("redis.arrays.lazyconnect")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_lazy_connect TSRMLS_CC);
}
- if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_lazy_connect), name, name_len)) != NULL) {
- if (Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
+ if ((z_data = zend_hash_str_find(Z_ARRVAL(z_params_lazy_connect), name, name_len)) != NULL) {
+ if (Z_TYPE_P(z_data) == IS_STRING && strncmp(Z_STRVAL_P(z_data), "1", 1) == 0) {
b_lazy_connect = 1;
}
}
-
+
/* find connect timeout option */
- array_init(&z_params_connect_timeout);
+ array_init(&z_params_connect_timeout);
if ((iptr = INI_STR("redis.arrays.connecttimeout")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_connect_timeout TSRMLS_CC);
}
@@ -298,7 +298,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
}
/* find read timeout option */
- array_init(&z_params_read_timeout);
+ array_init(&z_params_read_timeout);
if ((iptr = INI_STR("redis.arrays.readtimeout")) != NULL) {
sapi_module.treat_data(PARSE_STRING, estrdup(iptr), &z_params_read_timeout TSRMLS_CC);
}
@@ -312,15 +312,15 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
}
}
-
- /* create RedisArray object */
- ra = ra_make_array(hHosts, &z_fun, &z_dist, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout TSRMLS_CC);
+
+ /* create RedisArray object */
+ ra = ra_make_array(hHosts, &z_fun, &z_dist, hPrev, b_index, b_pconnect, l_retry_interval, b_lazy_connect, d_connect_timeout, read_timeout TSRMLS_CC);
if (ra) {
ra->auto_rehash = b_autorehash;
if(ra->prev) ra->prev->auto_rehash = b_autorehash;
}
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_params_hosts);
zval_dtor(&z_params_prev);
zval_dtor(&z_params_funs);
@@ -335,7 +335,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
zval_dtor(&z_dist);
zval_dtor(&z_fun);
- return ra;
+ return ra;
}
RedisArray *
@@ -346,17 +346,17 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
if (!hosts || (count = zend_hash_num_elements(hosts)) == 0) return NULL;
- /* create object */
- ra = emalloc(sizeof(RedisArray));
- ra->hosts = ecalloc(count, sizeof(char *));
- ra->redis = ecalloc(count, sizeof(zval));
- ra->count = 0;
- ra->z_multi_exec = NULL;
- ra->index = b_index;
- ra->auto_rehash = 0;
- ra->pconnect = b_pconnect;
- ra->connect_timeout = connect_timeout;
- ra->read_timeout = read_timeout;
+ /* create object */
+ ra = emalloc(sizeof(RedisArray));
+ ra->hosts = ecalloc(count, sizeof(char *));
+ ra->redis = ecalloc(count, sizeof(zval));
+ ra->count = 0;
+ ra->z_multi_exec = NULL;
+ ra->index = b_index;
+ ra->auto_rehash = 0;
+ ra->pconnect = b_pconnect;
+ ra->connect_timeout = connect_timeout;
+ ra->read_timeout = read_timeout;
if (ra_load_hosts(ra, hosts, retry_interval, b_lazy_connect TSRMLS_CC) == NULL || !ra->count) {
for (i = 0; i < ra->count; ++i) {
@@ -373,10 +373,10 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
/* init array data structures */
ra_init_function_table(ra);
- /* Set hash function and distribtor if provided */
+ /* Set hash function and distribtor if provided */
ZVAL_ZVAL(&ra->z_fun, z_fun, 1, 0);
ZVAL_ZVAL(&ra->z_dist, z_dist, 1, 0);
-
+
return ra;
}
@@ -388,18 +388,18 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
char *out = NULL;
zval z_ret, z_argv;
- /* check that we can call the extractor function */
+ /* check that we can call the extractor function */
#if (PHP_MAJOR_VERSION < 7)
if (!zend_is_callable_ex(&ra->z_fun, NULL, 0, NULL, NULL, NULL, NULL TSRMLS_CC)) {
#else
if (!zend_is_callable_ex(&ra->z_fun, NULL, 0, NULL, NULL, NULL)) {
#endif
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not call extractor function");
- return NULL;
- }
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not call extractor function");
+ return NULL;
+ }
ZVAL_NULL(&z_ret);
- /* call extraction function */
+ /* call extraction function */
ZVAL_STRINGL(&z_argv, key, key_len);
call_user_function(EG(function_table), NULL, &ra->z_fun, &z_ret, 1, &z_argv);
@@ -408,24 +408,24 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
out = estrndup(Z_STRVAL(z_ret), *out_len);
}
- zval_dtor(&z_argv);
- zval_dtor(&z_ret);
- return out;
+ zval_dtor(&z_argv);
+ zval_dtor(&z_ret);
+ return out;
}
static char *
ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS_DC) {
- char *start, *end;
- *out_len = key_len;
+ char *start, *end;
+ *out_len = key_len;
- if (Z_TYPE(ra->z_fun) != IS_NULL) {
- return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);
+ if (Z_TYPE(ra->z_fun) != IS_NULL) {
+ return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);
} else if ((start = strchr(key, '{')) == NULL || (end = strchr(start + 1, '}')) == NULL) {
return estrndup(key, key_len);
}
- /* found substring */
- *out_len = end - start - 1;
+ /* found substring */
+ *out_len = end - start - 1;
return estrndup(start + 1, *out_len);
}
@@ -436,25 +436,25 @@ ra_call_distributor(RedisArray *ra, const char *key, int key_len TSRMLS_DC)
int ret;
zval z_ret, z_argv;
- /* check that we can call the extractor function */
+ /* check that we can call the extractor function */
#if (PHP_MAJOR_VERSION < 7)
if (!zend_is_callable_ex(&ra->z_dist, NULL, 0, NULL, NULL, NULL, NULL TSRMLS_CC)) {
#else
if (!zend_is_callable_ex(&ra->z_dist, NULL, 0, NULL, NULL, NULL)) {
#endif
- php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not call distributor function");
- return -1;
- }
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Could not call distributor function");
+ return -1;
+ }
ZVAL_NULL(&z_ret);
- /* call extraction function */
+ /* call extraction function */
ZVAL_STRINGL(&z_argv, key, key_len);
call_user_function(EG(function_table), NULL, &ra->z_dist, &z_ret, 1, &z_argv);
ret = (Z_TYPE(z_ret) == IS_LONG) ? Z_LVAL(z_ret) : -1;
zval_dtor(&z_argv);
- zval_dtor(&z_ret);
+ zval_dtor(&z_ret);
return ret;
}
@@ -483,7 +483,7 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
CRC32(ret, (unsigned char)out[i]);
}
hash = (ret ^ 0xffffffff);
-
+
/* get position on ring */
pos = (int)(hash * ra->count / 0xffffffff);
}
@@ -497,23 +497,23 @@ ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_D
zval *
ra_find_node_by_name(RedisArray *ra, const char *host, int host_len TSRMLS_DC) {
- int i;
- for(i = 0; i < ra->count; ++i) {
- if(strncmp(ra->hosts[i], host, host_len) == 0) {
- return &ra->redis[i];
- }
- }
- return NULL;
+ int i;
+ for(i = 0; i < ra->count; ++i) {
+ if(strncmp(ra->hosts[i], host, host_len) == 0) {
+ return &ra->redis[i];
+ }
+ }
+ return NULL;
}
void
ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
- zval z_fun_multi, z_ret;
- zval z_args[1];
+ zval z_fun_multi, z_ret;
+ zval z_args[1];
- /* run MULTI */
- ZVAL_STRINGL(&z_fun_multi, "MULTI", 5);
+ /* run MULTI */
+ ZVAL_STRINGL(&z_fun_multi, "MULTI", 5);
ZVAL_LONG(&z_args[0], multi_value);
call_user_function(&redis_ce->function_table, z_redis, &z_fun_multi, &z_ret, 1, z_args);
zval_dtor(&z_fun_multi);
@@ -523,39 +523,39 @@ ra_index_multi(zval *z_redis, long multi_value TSRMLS_DC) {
static void
ra_index_change_keys(const char *cmd, zval *z_keys, zval *z_redis TSRMLS_DC) {
- int i, argc;
+ int i, argc;
zval z_fun, z_ret, *z_args;
- /* alloc */
- argc = 1 + zend_hash_num_elements(Z_ARRVAL_P(z_keys));
+ /* alloc */
+ argc = 1 + zend_hash_num_elements(Z_ARRVAL_P(z_keys));
z_args = ecalloc(argc, sizeof(zval));
- /* prepare first parameters */
- ZVAL_STRING(&z_fun, cmd);
+ /* prepare first parameters */
+ ZVAL_STRING(&z_fun, cmd);
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
- /* prepare keys */
- for(i = 0; i < argc - 1; ++i) {
+ /* prepare keys */
+ for(i = 0; i < argc - 1; ++i) {
zval *zv = zend_hash_index_find(Z_ARRVAL_P(z_keys), i);
if (zv == NULL) {
ZVAL_NULL(&z_args[i+1]);
} else {
z_args[i+1] = *zv;
}
- }
+ }
- /* run cmd */
+ /* run cmd */
call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, argc, z_args);
zval_dtor(&z_args[0]);
zval_dtor(&z_fun);
zval_dtor(&z_ret);
- efree(z_args); /* free container */
+ efree(z_args); /* free container */
}
void
ra_index_del(zval *z_keys, zval *z_redis TSRMLS_DC) {
- ra_index_change_keys("SREM", z_keys, z_redis TSRMLS_CC);
+ ra_index_change_keys("SREM", z_keys, z_redis TSRMLS_CC);
}
void
@@ -564,14 +564,14 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
zval z_keys, *z_val;
zend_string *zkey;
ulong idx;
- /* Initialize key array */
+ /* Initialize key array */
#if PHP_VERSION_ID > 50300
- array_init_size(&z_keys, zend_hash_num_elements(Z_ARRVAL_P(z_pairs)));
+ array_init_size(&z_keys, zend_hash_num_elements(Z_ARRVAL_P(z_pairs)));
#else
- array_init(&z_keys);
+ array_init(&z_keys);
#endif
- /* Go through input array and add values to the key array */
+ /* Go through input array and add values to the key array */
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(z_pairs), idx, zkey, z_val) {
zval zv, *z_new = &zv;
#if (PHP_MAJOR_VERSION < 7)
@@ -587,11 +587,11 @@ ra_index_keys(zval *z_pairs, zval *z_redis TSRMLS_DC) {
zend_hash_next_index_insert(Z_ARRVAL(z_keys), z_new);
} ZEND_HASH_FOREACH_END();
- /* add keys to index */
- ra_index_change_keys("SADD", &z_keys, z_redis TSRMLS_CC);
+ /* add keys to index */
+ ra_index_change_keys("SADD", &z_keys, z_redis TSRMLS_CC);
- /* cleanup */
- zval_dtor(&z_keys);
+ /* cleanup */
+ zval_dtor(&z_keys);
}
void
@@ -599,13 +599,13 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
zval z_fun_sadd, z_ret, z_args[2];
- /* prepare args */
- ZVAL_STRINGL(&z_fun_sadd, "SADD", 4);
+ /* prepare args */
+ ZVAL_STRINGL(&z_fun_sadd, "SADD", 4);
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
ZVAL_STRINGL(&z_args[1], key, key_len);
- /* run SADD */
+ /* run SADD */
call_user_function(&redis_ce->function_table, z_redis, &z_fun_sadd, &z_ret, 2, z_args);
zval_dtor(&z_fun_sadd);
zval_dtor(&z_args[1]);
@@ -616,126 +616,126 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
void
ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC) {
- zval z_fun_exec, z_ret, *zp_tmp;
+ zval z_fun_exec, z_ret, *zp_tmp;
- /* run EXEC */
- ZVAL_STRINGL(&z_fun_exec, "EXEC", 4);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL);
+ /* run EXEC */
+ ZVAL_STRINGL(&z_fun_exec, "EXEC", 4);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun_exec, &z_ret, 0, NULL);
zval_dtor(&z_fun_exec);
- /* extract first element of exec array and put into return_value. */
- if(Z_TYPE(z_ret) == IS_ARRAY) {
- if(return_value) {
- if(keep_all) {
+ /* extract first element of exec array and put into return_value. */
+ if(Z_TYPE(z_ret) == IS_ARRAY) {
+ if(return_value) {
+ if(keep_all) {
zp_tmp = &z_ret;
RETVAL_ZVAL(zp_tmp, 1, 0);
- } else if ((zp_tmp = zend_hash_index_find(Z_ARRVAL(z_ret), 0)) != NULL) {
+ } else if ((zp_tmp = zend_hash_index_find(Z_ARRVAL(z_ret), 0)) != NULL) {
RETVAL_ZVAL(zp_tmp, 1, 0);
- }
- }
- }
- zval_dtor(&z_ret);
+ }
+ }
+ }
+ zval_dtor(&z_ret);
- /* zval *zptr = &z_ret; */
- /* php_var_dump(&zptr, 0 TSRMLS_CC); */
+ /* zval *zptr = &z_ret; */
+ /* php_var_dump(&zptr, 0 TSRMLS_CC); */
}
void
ra_index_discard(zval *z_redis, zval *return_value TSRMLS_DC) {
- zval z_fun_discard, z_ret;
+ zval z_fun_discard, z_ret;
- /* run DISCARD */
- ZVAL_STRINGL(&z_fun_discard, "DISCARD", 7);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL);
+ /* run DISCARD */
+ ZVAL_STRINGL(&z_fun_discard, "DISCARD", 7);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun_discard, &z_ret, 0, NULL);
- zval_dtor(&z_fun_discard);
- zval_dtor(&z_ret);
+ zval_dtor(&z_fun_discard);
+ zval_dtor(&z_ret);
}
void
ra_index_unwatch(zval *z_redis, zval *return_value TSRMLS_DC) {
- zval z_fun_unwatch, z_ret;
+ zval z_fun_unwatch, z_ret;
- /* run UNWATCH */
- ZVAL_STRINGL(&z_fun_unwatch, "UNWATCH", 7);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL);
+ /* run UNWATCH */
+ ZVAL_STRINGL(&z_fun_unwatch, "UNWATCH", 7);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun_unwatch, &z_ret, 0, NULL);
- zval_dtor(&z_fun_unwatch);
- zval_dtor(&z_ret);
+ zval_dtor(&z_fun_unwatch);
+ zval_dtor(&z_ret);
}
zend_bool
ra_is_write_cmd(RedisArray *ra, const char *cmd, int cmd_len) {
- zend_bool ret;
- int i;
- char *cmd_up = emalloc(1 + cmd_len);
- /* convert to uppercase */
- for(i = 0; i < cmd_len; ++i)
- cmd_up[i] = toupper(cmd[i]);
- cmd_up[cmd_len] = 0;
+ zend_bool ret;
+ int i;
+ char *cmd_up = emalloc(1 + cmd_len);
+ /* convert to uppercase */
+ for(i = 0; i < cmd_len; ++i)
+ cmd_up[i] = toupper(cmd[i]);
+ cmd_up[cmd_len] = 0;
- ret = zend_hash_str_exists(ra->pure_cmds, cmd_up, cmd_len);
+ ret = zend_hash_str_exists(ra->pure_cmds, cmd_up, cmd_len);
- efree(cmd_up);
- return !ret;
+ efree(cmd_up);
+ return !ret;
}
/* run TYPE to find the type */
static zend_bool
ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long *res TSRMLS_DC) {
- int i = 0;
- zval z_fun, z_ret, z_arg, *z_data;
- long success = 1;
+ int i = 0;
+ zval z_fun, z_ret, z_arg, *z_data;
+ long success = 1;
- /* Pipelined */
- ra_index_multi(z_from, PIPELINE TSRMLS_CC);
+ /* Pipelined */
+ ra_index_multi(z_from, PIPELINE TSRMLS_CC);
- /* prepare args */
- ZVAL_STRINGL(&z_arg, key, key_len);
+ /* prepare args */
+ ZVAL_STRINGL(&z_arg, key, key_len);
- /* run TYPE */
+ /* run TYPE */
ZVAL_NULL(&z_ret);
- ZVAL_STRINGL(&z_fun, "TYPE", 4);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
+ ZVAL_STRINGL(&z_fun, "TYPE", 4);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
zval_dtor(&z_fun);
- zval_dtor(&z_ret);
+ zval_dtor(&z_ret);
- /* run TYPE */
+ /* run TYPE */
ZVAL_NULL(&z_ret);
- ZVAL_STRINGL(&z_fun, "TTL", 3);
- call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
+ ZVAL_STRINGL(&z_fun, "TTL", 3);
+ call_user_function(&redis_ce->function_table, z_redis, &z_fun, &z_ret, 1, &z_arg);
zval_dtor(&z_fun);
- zval_dtor(&z_ret);
+ zval_dtor(&z_ret);
- /* Get the result from the pipeline. */
- ra_index_exec(z_from, &z_ret, 1 TSRMLS_CC);
+ /* Get the result from the pipeline. */
+ ra_index_exec(z_from, &z_ret, 1 TSRMLS_CC);
if (Z_TYPE(z_ret) == IS_ARRAY) {
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(z_ret), z_data) {
if (z_data == NULL || Z_TYPE_P(z_data) != IS_LONG) {
- success = 0;
- break;
- }
- /* Get the result - Might change in the future to handle doubles as well */
- res[i++] = Z_LVAL_P(z_data);
+ success = 0;
+ break;
+ }
+ /* Get the result - Might change in the future to handle doubles as well */
+ res[i++] = Z_LVAL_P(z_data);
} ZEND_HASH_FOREACH_END();
- }
- zval_dtor(&z_arg);
- zval_dtor(&z_ret);
- return success;
+ }
+ zval_dtor(&z_arg);
+ zval_dtor(&z_ret);
+ return success;
}
/* delete key from source server index during rehashing */
static void
ra_remove_from_index(zval *z_redis, const char *key, int key_len TSRMLS_DC) {
- zval z_fun_srem, z_ret, z_args[2];
+ zval z_fun_srem, z_ret, z_args[2];
- /* run SREM on source index */
- ZVAL_STRINGL(&z_fun_srem, "SREM", 4);
+ /* run SREM on source index */
+ ZVAL_STRINGL(&z_fun_srem, "SREM", 4);
ZVAL_STRINGL(&z_args[0], PHPREDIS_INDEX_NAME, sizeof(PHPREDIS_INDEX_NAME) - 1);
ZVAL_STRINGL(&z_args[1], key, key_len);
@@ -753,26 +753,26 @@ ra_remove_from_index(zval *z_redis, const char *key, int key_len TSRMLS_DC) {
static zend_bool
ra_del_key(const char *key, int key_len, zval *z_from TSRMLS_DC) {
- zval z_fun_del, z_ret, z_args[1];
+ zval z_fun_del, z_ret, z_args[1];
- /* in a transaction */
- ra_index_multi(z_from, MULTI TSRMLS_CC);
+ /* in a transaction */
+ ra_index_multi(z_from, MULTI TSRMLS_CC);
- /* run DEL on source */
- ZVAL_STRINGL(&z_fun_del, "DEL", 3);
- ZVAL_STRINGL(&z_args[0], key, key_len);
- call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args);
+ /* run DEL on source */
+ ZVAL_STRINGL(&z_fun_del, "DEL", 3);
+ ZVAL_STRINGL(&z_args[0], key, key_len);
+ call_user_function(&redis_ce->function_table, z_from, &z_fun_del, &z_ret, 1, z_args);
zval_dtor(&z_fun_del);
zval_dtor(&z_args[0]);
zval_dtor(&z_ret);
- /* remove key from index */
- ra_remove_from_index(z_from, key, key_len TSRMLS_CC);
+ /* remove key from index */
+ ra_remove_from_index(z_from, key, key_len TSRMLS_CC);
- /* close transaction */
- ra_index_exec(z_from, NULL, 0 TSRMLS_CC);
+ /* close transaction */
+ ra_index_exec(z_from, NULL, 0 TSRMLS_CC);
- return 1;
+ return 1;
}
static zend_bool
@@ -780,80 +780,80 @@ ra_expire_key(const char *key, int key_len, zval *z_to, long ttl TSRMLS_DC) {
zval z_fun_expire, z_ret, z_args[2];
- if (ttl > 0)
- {
- /* run EXPIRE on target */
- ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6);
+ if (ttl > 0)
+ {
+ /* run EXPIRE on target */
+ ZVAL_STRINGL(&z_fun_expire, "EXPIRE", 6);
ZVAL_STRINGL(&z_args[0], key, key_len);
ZVAL_LONG(&z_args[1], ttl);
call_user_function(&redis_ce->function_table, z_to, &z_fun_expire, &z_ret, 2, z_args);
zval_dtor(&z_fun_expire);
zval_dtor(&z_args[0]);
zval_dtor(&z_ret);
- }
+ }
- return 1;
+ return 1;
}
static zend_bool
ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) {
zval z_fun_zrange, z_fun_zadd, z_ret, z_ret_dest, z_args[4], *z_zadd_args, *z_score_p;
- int i, count;
- HashTable *h_zset_vals;
+ int i, count;
+ HashTable *h_zset_vals;
zend_string *zkey;
- ulong idx;
-
- /* run ZRANGE key 0 -1 WITHSCORES on source */
- ZVAL_STRINGL(&z_fun_zrange, "ZRANGE", 6);
- ZVAL_STRINGL(&z_args[0], key, key_len);
- ZVAL_STRINGL(&z_args[1], "0", 1);
- ZVAL_STRINGL(&z_args[2], "-1", 2);
- ZVAL_BOOL(&z_args[3], 1);
- call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args);
+ ulong idx;
+
+ /* run ZRANGE key 0 -1 WITHSCORES on source */
+ ZVAL_STRINGL(&z_fun_zrange, "ZRANGE", 6);
+ ZVAL_STRINGL(&z_args[0], key, key_len);
+ ZVAL_STRINGL(&z_args[1], "0", 1);
+ ZVAL_STRINGL(&z_args[2], "-1", 2);
+ ZVAL_BOOL(&z_args[3], 1);
+ call_user_function(&redis_ce->function_table, z_from, &z_fun_zrange, &z_ret, 4, z_args);
zval_dtor(&z_fun_zrange);
zval_dtor(&z_args[2]);
zval_dtor(&z_args[1]);
zval_dtor(&z_args[0]);
- if(Z_TYPE(z_ret) != IS_ARRAY) { /* key not found or replaced */
- /* TODO: report? */
+ if(Z_TYPE(z_ret) != IS_ARRAY) { /* key not found or replaced */
+ /* TODO: report? */
zval_dtor(&z_ret);
- return 0;
- }
+ return 0;
+ }
- /* we now have an array of value → score pairs in z_ret. */
- h_zset_vals = Z_ARRVAL(z_ret);
+ /* we now have an array of value → score pairs in z_ret. */
+ h_zset_vals = Z_ARRVAL(z_ret);
- /* allocate argument array for ZADD */
- count = zend_hash_num_elements(h_zset_vals);
+ /* allocate argument array for ZADD */
+ count = zend_hash_num_elements(h_zset_vals);
z_zadd_args = ecalloc((1 + 2*count), sizeof(zval));
ZVAL_STRINGL(&z_zadd_args[0], key, key_len);
i = 1;
ZEND_HASH_FOREACH_KEY_VAL(h_zset_vals, idx, zkey, z_score_p) {
- /* add score */
+ /* add score */
ZVAL_DOUBLE(&z_zadd_args[i], Z_DVAL_P(z_score_p));
- /* add value */
+ /* add value */
if (zkey) {
ZVAL_STRINGL(&z_zadd_args[i+1], ZSTR_VAL(zkey), ZSTR_LEN(zkey));
} else {
ZVAL_LONG(&z_zadd_args[i+1], (long)idx);
}
- i += 2;
- } ZEND_HASH_FOREACH_END();
+ i += 2;
+ } ZEND_HASH_FOREACH_END();
- /* run ZADD on target */
- ZVAL_STRINGL(&z_fun_zadd, "ZADD", 4);
+ /* run ZADD on target */
+ ZVAL_STRINGL(&z_fun_zadd, "ZADD", 4);
call_user_function(&redis_ce->function_table, z_to, &z_fun_zadd, &z_ret_dest, 1 + 2 * count, z_zadd_args);
- /* Expire if needed */
- ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
+ /* Expire if needed */
+ ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_fun_zadd);
zval_dtor(&z_ret_dest);
zval_dtor(&z_ret);
@@ -864,7 +864,7 @@ ra_move_zset(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
}
efree(z_zadd_args);
- return 1;
+ return 1;
}
static zend_bool
@@ -872,116 +872,116 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
zval z_fun_get, z_fun_set, z_ret, z_args[3];
- /* run GET on source */
- ZVAL_STRINGL(&z_fun_get, "GET", 3);
+ /* run GET on source */
+ ZVAL_STRINGL(&z_fun_get, "GET", 3);
ZVAL_STRINGL(&z_args[0], key, key_len);
call_user_function(&redis_ce->function_table, z_from, &z_fun_get, &z_ret, 1, z_args);
zval_dtor(&z_fun_get);
- if(Z_TYPE(z_ret) != IS_STRING) { /* key not found or replaced */
- /* TODO: report? */
+ if(Z_TYPE(z_ret) != IS_STRING) { /* key not found or replaced */
+ /* TODO: report? */
zval_dtor(&z_args[0]);
zval_dtor(&z_ret);
- return 0;
- }
+ return 0;
+ }
- /* run SET on target */
- if (ttl > 0) {
+ /* run SET on target */
+ if (ttl > 0) {
ZVAL_STRINGL(&z_fun_set, "SETEX", 5);
ZVAL_LONG(&z_args[1], ttl);
ZVAL_STRINGL(&z_args[2], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
- zval_dtor(&z_ret); /* free memory from our previous call */
+ zval_dtor(&z_ret); /* free memory from our previous call */
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 3, z_args);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_args[2]);
} else {
ZVAL_STRINGL(&z_fun_set, "SET", 3);
ZVAL_STRINGL(&z_args[1], Z_STRVAL(z_ret), Z_STRLEN(z_ret)); /* copy z_ret to arg 1 */
- zval_dtor(&z_ret); /* free memory from our previous return value */
+ zval_dtor(&z_ret); /* free memory from our previous return value */
call_user_function(&redis_ce->function_table, z_to, &z_fun_set, &z_ret, 2, z_args);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_args[1]);
- }
+ }
zval_dtor(&z_fun_set);
zval_dtor(&z_args[0]);
zval_dtor(&z_ret);
- return 1;
+ return 1;
}
static zend_bool
ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) {
- zval z_fun_hgetall, z_fun_hmset, z_ret_dest, z_args[2];
+ zval z_fun_hgetall, z_fun_hmset, z_ret_dest, z_args[2];
- /* run HGETALL on source */
+ /* run HGETALL on source */
ZVAL_STRINGL(&z_args[0], key, key_len);
ZVAL_STRINGL(&z_fun_hgetall, "HGETALL", 7);
call_user_function(&redis_ce->function_table, z_from, &z_fun_hgetall, &z_args[1], 1, z_args);
zval_dtor(&z_fun_hgetall);
- if (Z_TYPE(z_args[1]) != IS_ARRAY) { /* key not found or replaced */
- /* TODO: report? */
+ if (Z_TYPE(z_args[1]) != IS_ARRAY) { /* key not found or replaced */
+ /* TODO: report? */
zval_dtor(&z_args[1]);
zval_dtor(&z_args[0]);
- return 0;
- }
+ return 0;
+ }
- /* run HMSET on target */
- ZVAL_STRINGL(&z_fun_hmset, "HMSET", 5);
- call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args);
+ /* run HMSET on target */
+ ZVAL_STRINGL(&z_fun_hmset, "HMSET", 5);
+ call_user_function(&redis_ce->function_table, z_to, &z_fun_hmset, &z_ret_dest, 2, z_args);
zval_dtor(&z_fun_hmset);
zval_dtor(&z_ret_dest);
- /* Expire if needed */
- ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
+ /* Expire if needed */
+ ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_args[1]);
zval_dtor(&z_args[0]);
- return 1;
+ return 1;
}
static zend_bool
ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
- int list_count, const char **cmd_list,
- int add_count, const char **cmd_add, long ttl TSRMLS_DC) {
+ int list_count, const char **cmd_list,
+ int add_count, const char **cmd_add, long ttl TSRMLS_DC) {
zval z_fun_retrieve, z_fun_sadd, z_ret, *z_retrieve_args, *z_sadd_args, *z_data_p;
- int count, i;
- HashTable *h_set_vals;
+ int count, i;
+ HashTable *h_set_vals;
- /* run retrieval command on source */
- ZVAL_STRING(&z_fun_retrieve, cmd_list[0]); /* set the command */
+ /* run retrieval command on source */
+ ZVAL_STRING(&z_fun_retrieve, cmd_list[0]); /* set the command */
z_retrieve_args = ecalloc(list_count, sizeof(zval));
- /* set the key */
+ /* set the key */
ZVAL_STRINGL(&z_retrieve_args[0], key, key_len);
- /* possibly add some other args if they were provided. */
- for(i = 1; i < list_count; ++i) {
+ /* possibly add some other args if they were provided. */
+ for(i = 1; i < list_count; ++i) {
ZVAL_STRING(&z_retrieve_args[i], cmd_list[i]);
- }
+ }
call_user_function(&redis_ce->function_table, z_from, &z_fun_retrieve, &z_ret, list_count, z_retrieve_args);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_fun_retrieve);
- for(i = 0; i < list_count; ++i) {
+ for(i = 0; i < list_count; ++i) {
zval_dtor(&z_retrieve_args[i]);
- }
- efree(z_retrieve_args);
+ }
+ efree(z_retrieve_args);
- if(Z_TYPE(z_ret) != IS_ARRAY) { /* key not found or replaced */
- /* TODO: report? */
+ if(Z_TYPE(z_ret) != IS_ARRAY) { /* key not found or replaced */
+ /* TODO: report? */
zval_dtor(&z_ret);
- return 0;
- }
+ return 0;
+ }
- /* run SADD/RPUSH on target */
- h_set_vals = Z_ARRVAL(z_ret);
- count = 1 + zend_hash_num_elements(h_set_vals);
- ZVAL_STRING(&z_fun_sadd, cmd_add[0]);
+ /* run SADD/RPUSH on target */
+ h_set_vals = Z_ARRVAL(z_ret);
+ count = 1 + zend_hash_num_elements(h_set_vals);
+ ZVAL_STRING(&z_fun_sadd, cmd_add[0]);
z_sadd_args = ecalloc(count, sizeof(zval));
ZVAL_STRINGL(&z_sadd_args[0], key, key_len);
@@ -997,88 +997,88 @@ ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
call_user_function(&redis_ce->function_table, z_to, &z_fun_sadd, &z_ret, count, z_sadd_args);
- /* cleanup */
+ /* cleanup */
zval_dtor(&z_fun_sadd);
for (i = 0; i < count; i++) {
zval_dtor(&z_sadd_args[i]);
}
- efree(z_sadd_args);
+ efree(z_sadd_args);
/* Clean up our output return value */
zval_dtor(&z_ret);
- /* Expire if needed */
- ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
+ /* Expire if needed */
+ ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC);
- return 1;
+ return 1;
}
static zend_bool
ra_move_set(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) {
- const char *cmd_list[] = {"SMEMBERS"};
- const char *cmd_add[] = {"SADD"};
- return ra_move_collection(key, key_len, z_from, z_to, 1, cmd_list, 1, cmd_add, ttl TSRMLS_CC);
+ const char *cmd_list[] = {"SMEMBERS"};
+ const char *cmd_add[] = {"SADD"};
+ return ra_move_collection(key, key_len, z_from, z_to, 1, cmd_list, 1, cmd_add, ttl TSRMLS_CC);
}
static zend_bool
ra_move_list(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) {
- const char *cmd_list[] = {"LRANGE", "0", "-1"};
- const char *cmd_add[] = {"RPUSH"};
- return ra_move_collection(key, key_len, z_from, z_to, 3, cmd_list, 1, cmd_add, ttl TSRMLS_CC);
+ const char *cmd_list[] = {"LRANGE", "0", "-1"};
+ const char *cmd_add[] = {"RPUSH"};
+ return ra_move_collection(key, key_len, z_from, z_to, 3, cmd_list, 1, cmd_add, ttl TSRMLS_CC);
}
void
ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC) {
- long res[2] = {0}, type, ttl;
- zend_bool success = 0;
- if (ra_get_key_type(z_from, key, key_len, z_from, res TSRMLS_CC)) {
- type = res[0];
- ttl = res[1];
- /* open transaction on target server */
- ra_index_multi(z_to, MULTI TSRMLS_CC);
- switch(type) {
- case REDIS_STRING:
- success = ra_move_string(key, key_len, z_from, z_to, ttl TSRMLS_CC);
- break;
-
- case REDIS_SET:
- success = ra_move_set(key, key_len, z_from, z_to, ttl TSRMLS_CC);
- break;
-
- case REDIS_LIST:
- success = ra_move_list(key, key_len, z_from, z_to, ttl TSRMLS_CC);
- break;
-
- case REDIS_ZSET:
- success = ra_move_zset(key, key_len, z_from, z_to, ttl TSRMLS_CC);
- break;
-
- case REDIS_HASH:
- success = ra_move_hash(key, key_len, z_from, z_to, ttl TSRMLS_CC);
- break;
-
- default:
- /* TODO: report? */
- break;
- }
- }
-
- if(success) {
- ra_del_key(key, key_len, z_from TSRMLS_CC);
- ra_index_key(key, key_len, z_to TSRMLS_CC);
- }
-
- /* close transaction */
- ra_index_exec(z_to, NULL, 0 TSRMLS_CC);
+ long res[2] = {0}, type, ttl;
+ zend_bool success = 0;
+ if (ra_get_key_type(z_from, key, key_len, z_from, res TSRMLS_CC)) {
+ type = res[0];
+ ttl = res[1];
+ /* open transaction on target server */
+ ra_index_multi(z_to, MULTI TSRMLS_CC);
+ switch(type) {
+ case REDIS_STRING:
+ success = ra_move_string(key, key_len, z_from, z_to, ttl TSRMLS_CC);
+ break;
+
+ case REDIS_SET:
+ success = ra_move_set(key, key_len, z_from, z_to, ttl TSRMLS_CC);
+ break;
+
+ case REDIS_LIST:
+ success = ra_move_list(key, key_len, z_from, z_to, ttl TSRMLS_CC);
+ break;
+
+ case REDIS_ZSET:
+ success = ra_move_zset(key, key_len, z_from, z_to, ttl TSRMLS_CC);
+ break;
+
+ case REDIS_HASH:
+ success = ra_move_hash(key, key_len, z_from, z_to, ttl TSRMLS_CC);
+ break;
+
+ default:
+ /* TODO: report? */
+ break;
+ }
+ }
+
+ if(success) {
+ ra_del_key(key, key_len, z_from TSRMLS_CC);
+ ra_index_key(key, key_len, z_to TSRMLS_CC);
+ }
+
+ /* close transaction */
+ ra_index_exec(z_to, NULL, 0 TSRMLS_CC);
}
/* callback with the current progress, with hostname and count */
static void
zval_rehash_callback(zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache,
- const char *hostname, long count TSRMLS_DC) {
+ const char *hostname, long count TSRMLS_DC) {
zval zv, *z_ret = &zv;
@@ -1105,13 +1105,13 @@ zval_rehash_callback(zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache,
z_cb->params = z_args;
z_cb->retval = z_ret;
#endif
- z_cb->no_separation = 0;
- z_cb->param_count = 2;
+ z_cb->no_separation = 0;
+ z_cb->param_count = 2;
- /* run cb(hostname, count) */
- zend_call_function(z_cb, z_cb_cache TSRMLS_CC);
+ /* run cb(hostname, count) */
+ zend_call_function(z_cb, z_cb_cache TSRMLS_CC);
- /* cleanup */
+ /* cleanup */
#if (PHP_MAJOR_VERSION < 7)
zval_ptr_dtor(&z_host);
zval_ptr_dtor(&z_count);
@@ -1123,7 +1123,7 @@ zval_rehash_callback(zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache,
static void
ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool b_index,
- zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache TSRMLS_DC) {
+ zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache TSRMLS_DC) {
HashTable *h_keys;
long count = 0;
@@ -1152,10 +1152,10 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
return;
}
- /* callback */
- if(z_cb && z_cb_cache) {
- zval_rehash_callback(z_cb, z_cb_cache, hostname, count TSRMLS_CC);
- }
+ /* callback */
+ if(z_cb && z_cb_cache) {
+ zval_rehash_callback(z_cb, z_cb_cache, hostname, count TSRMLS_CC);
+ }
/* for each key, redistribute */
ZEND_HASH_FOREACH_VAL(h_keys, z_ele) {
@@ -1175,14 +1175,14 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
void
ra_rehash(RedisArray *ra, zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache TSRMLS_DC) {
- int i;
+ int i;
- /* redistribute the data, server by server. */
- if(!ra->prev)
- return; /* TODO: compare the two rings for equality */
+ /* redistribute the data, server by server. */
+ if(!ra->prev)
+ return; /* TODO: compare the two rings for equality */
- for(i = 0; i < ra->prev->count; ++i) {
- ra_rehash_server(ra, &ra->prev->redis[i], ra->prev->hosts[i], ra->index, z_cb, z_cb_cache TSRMLS_CC);
- }
+ for(i = 0; i < ra->prev->count; ++i) {
+ ra_rehash_server(ra, &ra->prev->redis[i], ra->prev->hosts[i], ra->index, z_cb, z_cb_cache TSRMLS_CC);
+ }
}
diff --git a/redis_cluster.c b/redis_cluster.c
index b241e561..0dacd926 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -332,14 +332,14 @@ create_cluster_context(zend_class_entry *class_type TSRMLS_DC) {
return retval;
#else
- object_properties_init(&cluster->std, class_type);
- memcpy(&RedisCluster_handlers, zend_get_std_object_handlers(), sizeof(RedisCluster_handlers));
- RedisCluster_handlers.offset = XtOffsetOf(redisCluster, std);
+ object_properties_init(&cluster->std, class_type);
+ memcpy(&RedisCluster_handlers, zend_get_std_object_handlers(), sizeof(RedisCluster_handlers));
+ RedisCluster_handlers.offset = XtOffsetOf(redisCluster, std);
RedisCluster_handlers.free_obj = free_cluster_context;
- cluster->std.handlers = &RedisCluster_handlers;
+ cluster->std.handlers = &RedisCluster_handlers;
- return &cluster->std;
+ return &cluster->std;
#endif
}
@@ -606,21 +606,21 @@ static int get_key_val_ht(redisCluster *c, HashTable *ht, HashPosition *ptr,
clusterKeyValHT *kv TSRMLS_DC)
{
zval *z_val;
- zend_ulong idx;
+ zend_ulong idx;
// Grab the key, convert it to a string using provided kbuf buffer if it's
// a LONG style key
#if (PHP_MAJOR_VERSION < 7)
- uint key_len;
- switch(zend_hash_get_current_key_ex(ht, &(kv->key), &key_len, &idx, 0, ptr)) {
- case HASH_KEY_IS_STRING:
- kv->key_len = (int)(key_len-1);
+ uint key_len;
+ switch(zend_hash_get_current_key_ex(ht, &(kv->key), &key_len, &idx, 0, ptr)) {
+ case HASH_KEY_IS_STRING:
+ kv->key_len = (int)(key_len-1);
#else
- zend_string *zkey;
- switch (zend_hash_get_current_key_ex(ht, &zkey, &idx, ptr)) {
- case HASH_KEY_IS_STRING:
- kv->key_len = ZSTR_LEN(zkey);
- kv->key = ZSTR_VAL(zkey);
+ zend_string *zkey;
+ switch (zend_hash_get_current_key_ex(ht, &zkey, &idx, ptr)) {
+ case HASH_KEY_IS_STRING:
+ kv->key_len = ZSTR_LEN(zkey);
+ kv->key = ZSTR_VAL(zkey);
#endif
break;
case HASH_KEY_IS_LONG:
@@ -743,7 +743,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
// it's the first iteration every time, needlessly
zend_hash_internal_pointer_reset_ex(ht_arr, &ptr);
if(get_key_ht(c, ht_arr, &ptr, &kv TSRMLS_CC)<0) {
- efree(z_args);
+ efree(z_args);
return -1;
}
@@ -765,7 +765,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
- efree(z_args);
+ efree(z_args);
return -1;
}
@@ -780,7 +780,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zend_hash_destroy(ht_arr);
efree(ht_arr);
}
- efree(z_args);
+ efree(z_args);
return -1;
}
}
@@ -797,7 +797,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zend_hash_move_forward_ex(ht_arr, &ptr);
}
- efree(z_args);
+ efree(z_args);
// If we've got straggler(s) process them
if(mc.argc > 0) {
@@ -2246,10 +2246,10 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
zend_string_release(zstr);
if(key_free) efree(key);
} else if (Z_TYPE_P(z_arg) == IS_ARRAY &&
- (z_host = zend_hash_index_find(Z_ARRVAL_P(z_arg), 0)) != NULL &&
- (z_port = zend_hash_index_find(Z_ARRVAL_P(z_arg), 1)) != NULL &&
- Z_TYPE_P(z_host) == IS_STRING && Z_TYPE_P(z_port) == IS_LONG
- ) {
+ (z_host = zend_hash_index_find(Z_ARRVAL_P(z_arg), 0)) != NULL &&
+ (z_port = zend_hash_index_find(Z_ARRVAL_P(z_arg), 1)) != NULL &&
+ Z_TYPE_P(z_host) == IS_STRING && Z_TYPE_P(z_port) == IS_LONG
+ ) {
/* Attempt to find this specific node by host:port */
slot = cluster_find_slot(c,(const char *)Z_STRVAL_P(z_host),
(unsigned short)Z_LVAL_P(z_port));