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:
authormichael-grunder <michael.grunder@gmail.com>2018-02-17 20:47:28 +0300
committermichael-grunder <michael.grunder@gmail.com>2018-02-17 20:47:28 +0300
commita4afe919094cdc2f71fa59d76f4c7f5a08bd1d00 (patch)
tree93088d9972b19de4c8781cecf55f4dc8fd5f4d6d /redis_cluster.c
parent78fa97684ee85f4848ba78e07527deb6caff2fe2 (diff)
Some style normalization
Diffstat (limited to 'redis_cluster.c')
-rw-r--r--redis_cluster.c288
1 files changed, 144 insertions, 144 deletions
diff --git a/redis_cluster.c b/redis_cluster.c
index ede16b94..8b802011 100644
--- a/redis_cluster.c
+++ b/redis_cluster.c
@@ -279,7 +279,7 @@ static void ht_free_seed(zval *data)
#endif
{
RedisSock *redis_sock = *(RedisSock**)data;
- if(redis_sock) redis_free_socket(redis_sock);
+ if (redis_sock) redis_free_socket(redis_sock);
}
/* Free redisClusterNode objects we've stored */
@@ -366,7 +366,7 @@ free_cluster_context(zend_object *object) {
redisCluster *cluster = (redisCluster*)((char*)(object) - XtOffsetOf(redisCluster, std));
#endif
// Free any allocated prefix, as well as the struct
- if(cluster->flags->prefix) efree(cluster->flags->prefix);
+ if (cluster->flags->prefix) efree(cluster->flags->prefix);
efree(cluster->flags);
// Free seeds HashTable itself
@@ -391,19 +391,19 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
double read_timeout, int persistent TSRMLS_DC)
{
// Validate timeout
- if(timeout < 0L || timeout > INT_MAX) {
+ if (timeout < 0L || timeout > INT_MAX) {
zend_throw_exception(redis_cluster_exception_ce,
"Invalid timeout", 0 TSRMLS_CC);
}
// Validate our read timeout
- if(read_timeout < 0L || read_timeout > INT_MAX) {
+ if (read_timeout < 0L || read_timeout > INT_MAX) {
zend_throw_exception(redis_cluster_exception_ce,
"Invalid read timeout", 0 TSRMLS_CC);
}
/* Make sure there are some seeds */
- if(zend_hash_num_elements(ht_seeds)==0) {
+ if (zend_hash_num_elements(ht_seeds) == 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Must pass seeds", 0 TSRMLS_CC);
}
@@ -430,7 +430,7 @@ void redis_cluster_init(redisCluster *c, HashTable *ht_seeds, double timeout,
void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
zval z_seeds, z_timeout, z_read_timeout, z_persistent, *z_value;
char *iptr;
- double timeout=0, read_timeout=0;
+ double timeout = 0, read_timeout = 0;
int persistent = 0;
HashTable *ht_seeds = NULL;
@@ -506,7 +506,7 @@ void redis_cluster_load(redisCluster *c, char *name, int name_len TSRMLS_DC) {
/* Create a RedisCluster Object */
PHP_METHOD(RedisCluster, __construct) {
- zval *object, *z_seeds=NULL;
+ zval *object, *z_seeds = NULL;
char *name;
strlen_t name_len;
double timeout = 0.0, read_timeout = 0.0;
@@ -514,16 +514,16 @@ PHP_METHOD(RedisCluster, __construct) {
redisCluster *context = GET_CONTEXT();
// Parse arguments
- if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(),
"Os!|addb", &object, redis_cluster_ce, &name,
&name_len, &z_seeds, &timeout,
- &read_timeout, &persistent)==FAILURE)
+ &read_timeout, &persistent) == FAILURE)
{
RETURN_FALSE;
}
// Require a name
- if(name_len == 0 && ZEND_NUM_ARGS() < 2) {
+ if (name_len == 0 && ZEND_NUM_ARGS() < 2) {
zend_throw_exception(redis_cluster_exception_ce,
"You must specify a name or pass seeds!",
0 TSRMLS_CC);
@@ -578,8 +578,8 @@ distcmd_resp_handler(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, short slot,
ctx->last = last;
// Attempt to send the command
- if(cluster_send_command(c,slot,mc->cmd.c,mc->cmd.len TSRMLS_CC)<0 ||
- c->err!=NULL)
+ if (cluster_send_command(c,slot,mc->cmd.c,mc->cmd.len TSRMLS_CC) < 0 ||
+ c->err != NULL)
{
cluster_multi_free(mc);
zval_dtor(z_ret);
@@ -587,7 +587,7 @@ distcmd_resp_handler(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c, short slot,
return -1;
}
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
// Process response now
cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, (void*)ctx);
} else {
@@ -720,7 +720,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zval *z_args;
HashTable *ht_arr;
HashPosition ptr;
- int i=1, argc = ZEND_NUM_ARGS(), ht_free=0;
+ int i = 1, argc = ZEND_NUM_ARGS(), ht_free = 0;
short slot;
/* If we don't have any arguments we're invalid */
@@ -755,7 +755,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
// Process the first key outside of our loop, so we don't have to check if
// 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) {
+ if (get_key_ht(c, ht_arr, &ptr, &kv TSRMLS_CC) < 0) {
efree(z_args);
return -1;
}
@@ -764,15 +764,15 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
cluster_multi_add(&mc, kv.key, kv.key_len);
// Free key if we prefixed
- if(kv.key_free) efree(kv.key);
+ if (kv.key_free) efree(kv.key);
// Move to the next key
zend_hash_move_forward_ex(ht_arr, &ptr);
// Iterate over keys 2...N
slot = kv.slot;
- while(zend_hash_has_more_elements_ex(ht_arr, &ptr)==SUCCESS) {
- if(get_key_ht(c, ht_arr, &ptr, &kv TSRMLS_CC)<0) {
+ while (zend_hash_has_more_elements_ex(ht_arr, &ptr) ==SUCCESS) {
+ if (get_key_ht(c, ht_arr, &ptr, &kv TSRMLS_CC) < 0) {
cluster_multi_free(&mc);
if (ht_free) {
zend_hash_destroy(ht_arr);
@@ -783,10 +783,10 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
}
// If the slots have changed, kick off the keys we've aggregated
- if(slot != kv.slot) {
+ if (slot != kv.slot) {
// Process this batch of MGET keys
- if(distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
- &mc, z_ret, i==argc, cb)<0)
+ if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
+ &mc, z_ret, i == argc, cb) < 0)
{
cluster_multi_free(&mc);
if (ht_free) {
@@ -802,7 +802,7 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
cluster_multi_add(&mc, kv.key, kv.key_len);
// Free key if we prefixed
- if(kv.key_free) efree(kv.key);
+ if (kv.key_free) efree(kv.key);
// Update the last slot we encountered, and the key we're on
slot = kv.slot;
@@ -813,9 +813,9 @@ static int cluster_mkey_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
efree(z_args);
// If we've got straggler(s) process them
- if(mc.argc > 0) {
- if(distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
- &mc, z_ret, 1, cb)<0)
+ if (mc.argc > 0) {
+ if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot,
+ &mc, z_ret, 1, cb) < 0)
{
cluster_multi_free(&mc);
if (ht_free) {
@@ -853,17 +853,17 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
zval *z_arr;
HashTable *ht_arr;
HashPosition ptr;
- int i=1, argc;
+ int i = 1, argc;
short slot;
// Parse our arguments
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &z_arr)==FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &z_arr) == FAILURE) {
return -1;
}
// No reason to send zero args
ht_arr = Z_ARRVAL_P(z_arr);
- if((argc = zend_hash_num_elements(ht_arr))==0) {
+ if ((argc = zend_hash_num_elements(ht_arr)) == 0) {
return -1;
}
@@ -875,27 +875,27 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
// Process the first key/value pair outside of our loop
zend_hash_internal_pointer_reset_ex(ht_arr, &ptr);
- if(get_key_val_ht(c, ht_arr, &ptr, &kv TSRMLS_CC)==-1) return -1;
+ if (get_key_val_ht(c, ht_arr, &ptr, &kv TSRMLS_CC) ==-1) return -1;
zend_hash_move_forward_ex(ht_arr, &ptr);
// Add this to our multi cmd, set slot, free key if we prefixed
cluster_multi_add(&mc, kv.key, kv.key_len);
cluster_multi_add(&mc, kv.val, kv.val_len);
- if(kv.key_free) efree(kv.key);
- if(kv.val_free) efree(kv.val);
+ if (kv.key_free) efree(kv.key);
+ if (kv.val_free) efree(kv.val);
// While we've got more keys to set
slot = kv.slot;
- while(zend_hash_has_more_elements_ex(ht_arr, &ptr)==SUCCESS) {
+ while (zend_hash_has_more_elements_ex(ht_arr, &ptr) ==SUCCESS) {
// Pull the next key/value pair
- if(get_key_val_ht(c, ht_arr, &ptr, &kv TSRMLS_CC)==-1) {
+ if (get_key_val_ht(c, ht_arr, &ptr, &kv TSRMLS_CC) ==-1) {
return -1;
}
// If the slots have changed, process responses
- if(slot != kv.slot) {
- if(distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c,
- slot, &mc, z_ret, i==argc, cb)<0)
+ if (slot != kv.slot) {
+ if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c,
+ slot, &mc, z_ret, i == argc, cb) < 0)
{
return -1;
}
@@ -906,8 +906,8 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
cluster_multi_add(&mc, kv.val, kv.val_len);
// Free our key and value if we need to
- if(kv.key_free) efree(kv.key);
- if(kv.val_free) efree(kv.val);
+ if (kv.key_free) efree(kv.key);
+ if (kv.val_free) efree(kv.val);
// Update our slot, increment position
slot = kv.slot;
@@ -918,9 +918,9 @@ static int cluster_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len,
}
// If we've got stragglers, process them too
- if(mc.argc > 0) {
- if(distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot, &mc,
- z_ret, 1, cb)<0)
+ if (mc.argc > 0) {
+ if (distcmd_resp_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, slot, &mc,
+ z_ret, 1, cb) < 0)
{
return -1;
}
@@ -953,7 +953,7 @@ static void cluster_generic_delete(INTERNAL_FUNCTION_PARAMETERS,
ZVAL_LONG(z_ret, 0);
// Parse args, process
- if(cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, kw, kw_len, z_ret,
+ if (cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, kw, kw_len, z_ret,
cluster_del_resp) < 0)
{
efree(z_ret);
@@ -984,8 +984,8 @@ PHP_METHOD(RedisCluster, mget) {
array_init(z_ret);
// Parse args, process
- if(cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MGET",
- sizeof("MGET")-1, z_ret, cluster_mbulk_mget_resp)<0)
+ if (cluster_mkey_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MGET",
+ sizeof("MGET")-1, z_ret, cluster_mbulk_mget_resp) < 0)
{
zval_dtor(z_ret);
efree(z_ret);
@@ -1006,8 +1006,8 @@ PHP_METHOD(RedisCluster, mset) {
ZVAL_TRUE(z_ret);
// Parse args and process. If we get a failure, free zval and return FALSE.
- if(cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSET",
- sizeof("MSET")-1, z_ret, cluster_mset_resp)==-1)
+ if (cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSET",
+ sizeof("MSET")-1, z_ret, cluster_mset_resp) ==-1)
{
efree(z_ret);
RETURN_FALSE;
@@ -1027,8 +1027,8 @@ PHP_METHOD(RedisCluster, msetnx) {
array_init(z_ret);
// Parse args and process. If we get a failure, free mem and return FALSE
- if(cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSETNX",
- sizeof("MSETNX")-1, z_ret, cluster_msetnx_resp)==-1)
+ if (cluster_mset_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "MSETNX",
+ sizeof("MSETNX")-1, z_ret, cluster_msetnx_resp) ==-1)
{
zval_dtor(z_ret);
efree(z_ret);
@@ -1077,8 +1077,8 @@ PHP_METHOD(RedisCluster, keys) {
zval zv, *z_ret = &zv;
int i, cmd_len;
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pat, &pat_len)
- ==FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pat, &pat_len)
+ == FAILURE)
{
RETURN_FALSE;
}
@@ -1095,7 +1095,7 @@ PHP_METHOD(RedisCluster, keys) {
ZEND_HASH_FOREACH_PTR(c->nodes, node) {
if (node == NULL) break;
if (cluster_send_slot(c, node->slot, cmd, cmd_len, TYPE_MULTIBULK
- TSRMLS_CC)<0)
+ TSRMLS_CC) < 0)
{
php_error_docref(0 TSRMLS_CC, E_ERROR, "Can't send KEYS to %s:%d",
ZSTR_VAL(node->sock->host), node->sock->port);
@@ -1105,7 +1105,7 @@ PHP_METHOD(RedisCluster, keys) {
/* Ensure we can get a response */
resp = cluster_read_resp(c TSRMLS_CC);
- if(!resp) {
+ if (!resp) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"Can't read response from %s:%d", ZSTR_VAL(node->sock->host),
node->sock->port);
@@ -1113,9 +1113,9 @@ PHP_METHOD(RedisCluster, keys) {
}
/* Iterate keys, adding to our big array */
- for(i=0;i<resp->elements;i++) {
+ for(i = 0; i < resp->elements; i++) {
/* Skip non bulk responses, they should all be bulk */
- if(resp->element[i]->type != TYPE_BULK) {
+ if (resp->element[i]->type != TYPE_BULK) {
continue;
}
@@ -1180,14 +1180,14 @@ PHP_METHOD(RedisCluster, srandmember) {
/* Treat as readonly */
c->readonly = CLUSTER_IS_ATOMIC(c);
- if(redis_srandmember_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags,
+ if (redis_srandmember_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags,
&cmd, &cmd_len, &slot, NULL, &have_count)
- ==FAILURE)
+ == FAILURE)
{
RETURN_FALSE;
}
- if(cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC)<0 || c->err!=NULL) {
+ if (cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC) < 0 || c->err != NULL) {
efree(cmd);
RETURN_FALSE;
}
@@ -1706,16 +1706,16 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
c->readonly = CLUSTER_IS_ATOMIC(c);
cluster_cb cb;
char *cmd; int cmd_len; short slot;
- int withscores=0;
+ int withscores = 0;
- if(fun(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,
- &withscores, &slot, NULL)==FAILURE)
+ if (fun(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,
+ &withscores, &slot, NULL) == FAILURE)
{
efree(cmd);
RETURN_FALSE;
}
- if(cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC)<0 || c->err!=NULL) {
+ if (cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC) < 0 || c->err != NULL) {
efree(cmd);
RETURN_FALSE;
}
@@ -1733,7 +1733,7 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
}
/* {{{ proto
- * array RedisCluster::zrange(string k, long s, long e, bool score=0) */
+ * array RedisCluster::zrange(string k, long s, long e, bool score = 0) */
PHP_METHOD(RedisCluster, zrange) {
generic_zrange_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZRANGE",
redis_zrange_cmd);
@@ -1741,7 +1741,7 @@ PHP_METHOD(RedisCluster, zrange) {
/* }}} */
/* {{{ proto
- * array RedisCluster::zrevrange(string k,long s,long e,bool scores=0) */
+ * array RedisCluster::zrevrange(string k,long s,long e,bool scores = 0) */
PHP_METHOD(RedisCluster, zrevrange) {
generic_zrange_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREVRANGE",
redis_zrange_cmd);
@@ -1818,13 +1818,13 @@ PHP_METHOD(RedisCluster, sort) {
redisCluster *c = GET_CONTEXT();
char *cmd; int cmd_len, have_store; short slot;
- if(redis_sort_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &have_store,
- &cmd, &cmd_len, &slot, NULL)==FAILURE)
+ if (redis_sort_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &have_store,
+ &cmd, &cmd_len, &slot, NULL) == FAILURE)
{
RETURN_FALSE;
}
- if(cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC)<0 || c->err!=NULL) {
+ if (cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC) < 0 || c->err != NULL) {
efree(cmd);
RETURN_FALSE;
}
@@ -1832,7 +1832,7 @@ PHP_METHOD(RedisCluster, sort) {
efree(cmd);
// Response type differs based on presence of STORE argument
- if(!have_store) {
+ if (!have_store) {
cluster_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
} else {
cluster_long_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
@@ -1845,13 +1845,13 @@ PHP_METHOD(RedisCluster, object) {
char *cmd; int cmd_len; short slot;
REDIS_REPLY_TYPE rtype;
- if(redis_object_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &rtype,
- &cmd, &cmd_len, &slot, NULL)==FAILURE)
+ if (redis_object_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, &rtype,
+ &cmd, &cmd_len, &slot, NULL) == FAILURE)
{
RETURN_FALSE;
}
- if(cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC)<0 || c->err!=NULL) {
+ if (cluster_send_command(c,slot,cmd,cmd_len TSRMLS_CC) < 0 || c->err != NULL) {
efree(cmd);
RETURN_FALSE;
}
@@ -1859,7 +1859,7 @@ PHP_METHOD(RedisCluster, object) {
efree(cmd);
// Use the correct response type
- if(rtype == TYPE_INT) {
+ if (rtype == TYPE_INT) {
cluster_long_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
} else {
cluster_bulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, NULL);
@@ -1887,23 +1887,23 @@ static void generic_unsub_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
short slot;
// There is not reason to unsubscribe outside of a subscribe loop
- if(c->subscribed_slot == -1) {
+ if (c->subscribed_slot == -1) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"You can't unsubscribe outside of a subscribe loop");
RETURN_FALSE;
}
// Call directly because we're going to set the slot manually
- if(redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw,
+ if (redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw,
&cmd, &cmd_len, &slot, &ctx)
- ==FAILURE)
+ == FAILURE)
{
RETURN_FALSE;
}
// This has to operate on our subscribe slot
- if(cluster_send_slot(c, c->subscribed_slot, cmd, cmd_len, TYPE_MULTIBULK
- TSRMLS_CC) ==FAILURE)
+ if (cluster_send_slot(c, c->subscribed_slot, cmd, cmd_len, TYPE_MULTIBULK
+ TSRMLS_CC) == FAILURE)
{
zend_throw_exception(redis_cluster_exception_ce,
"Failed to UNSUBSCRIBE within our subscribe loop!", 0 TSRMLS_CC);
@@ -2043,7 +2043,7 @@ PHP_METHOD(RedisCluster, _redir) {
size_t len;
len = snprintf(buf, sizeof(buf), "%s:%d", c->redir_host, c->redir_port);
- if(*c->redir_host && c->redir_host_len) {
+ if (*c->redir_host && c->redir_host_len) {
RETURN_STRINGL(buf, len);
} else {
RETURN_NULL();
@@ -2058,7 +2058,7 @@ PHP_METHOD(RedisCluster, _redir) {
PHP_METHOD(RedisCluster, multi) {
redisCluster *c = GET_CONTEXT();
- if(c->flags->mode == MULTI) {
+ if (c->flags->mode == MULTI) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"RedisCluster is already in MULTI mode, ignoring");
RETURN_FALSE;
@@ -2083,14 +2083,14 @@ PHP_METHOD(RedisCluster, watch) {
zend_string *zstr;
// Disallow in MULTI mode
- if(c->flags->mode == MULTI) {
+ if (c->flags->mode == MULTI) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"WATCH command not allowed in MULTI mode");
RETURN_FALSE;
}
// Don't need to process zero arguments
- if(!argc) RETURN_FALSE;
+ if (!argc) RETURN_FALSE;
// Create our distribution HashTable
ht_dist = cluster_dist_create();
@@ -2104,7 +2104,7 @@ PHP_METHOD(RedisCluster, watch) {
}
// Loop through arguments, prefixing if needed
- for(i=0;i<argc;i++) {
+ for(i = 0 ; i < argc; i++) {
// We'll need the key as a string
zstr = zval_get_string(&z_args[i]);
@@ -2141,7 +2141,7 @@ PHP_METHOD(RedisCluster, watch) {
}
// If we get a failure from this, we have to abort
- if (cluster_send_command(c,(short)slot,cmd.c,cmd.len TSRMLS_CC)==-1) {
+ if (cluster_send_command(c,(short)slot,cmd.c,cmd.len TSRMLS_CC) ==-1) {
RETURN_FALSE;
}
@@ -2166,11 +2166,11 @@ PHP_METHOD(RedisCluster, unwatch) {
short slot;
// Send UNWATCH to nodes that need it
- for(slot=0;slot<REDIS_CLUSTER_SLOTS;slot++) {
- if(c->master[slot] && SLOT_SOCK(c,slot)->watching) {
- if(cluster_send_slot(c, slot, RESP_UNWATCH_CMD,
+ for(slot = 0; slot < REDIS_CLUSTER_SLOTS; slot++) {
+ if (c->master[slot] && SLOT_SOCK(c,slot)->watching) {
+ if (cluster_send_slot(c, slot, RESP_UNWATCH_CMD,
sizeof(RESP_UNWATCH_CMD)-1,
- TYPE_LINE TSRMLS_CC)==-1)
+ TYPE_LINE TSRMLS_CC) ==-1)
{
CLUSTER_RETURN_BOOL(c, 0);
}
@@ -2189,16 +2189,16 @@ PHP_METHOD(RedisCluster, exec) {
clusterFoldItem *fi;
// Verify we are in fact in multi mode
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "RedisCluster is not in MULTI mode");
RETURN_FALSE;
}
// First pass, send EXEC and abort on failure
fi = c->multi_head;
- while(fi) {
- if(SLOT_SOCK(c, fi->slot)->mode == MULTI) {
- if(cluster_send_exec(c, fi->slot TSRMLS_CC)<0) {
+ while (fi) {
+ if (SLOT_SOCK(c, fi->slot)->mode == MULTI) {
+ if ( cluster_send_exec(c, fi->slot TSRMLS_CC) < 0) {
cluster_abort_exec(c TSRMLS_CC);
zend_throw_exception(redis_cluster_exception_ce,
@@ -2230,12 +2230,12 @@ PHP_METHOD(RedisCluster, exec) {
PHP_METHOD(RedisCluster, discard) {
redisCluster *c = GET_CONTEXT();
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cluster is not in MULTI mode");
RETURN_FALSE;
}
- if(cluster_abort_exec(c TSRMLS_CC)<0) {
+ if (cluster_abort_exec(c TSRMLS_CC) < 0) {
CLUSTER_RESET_MULTI(c);
}
@@ -2257,8 +2257,8 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
/* If it's a string, treat it as a key. Otherwise, look for a two
* element array */
- if(Z_TYPE_P(z_arg)==IS_STRING || Z_TYPE_P(z_arg)==IS_LONG ||
- Z_TYPE_P(z_arg)==IS_DOUBLE)
+ if (Z_TYPE_P(z_arg) ==IS_STRING || Z_TYPE_P(z_arg) ==IS_LONG ||
+ Z_TYPE_P(z_arg) ==IS_DOUBLE)
{
/* Allow for any scalar here */
zstr = zval_get_string(z_arg);
@@ -2269,7 +2269,7 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
key_free = redis_key_prefix(c->flags, &key, &key_len);
slot = cluster_hash_key(key, key_len);
zend_string_release(zstr);
- if(key_free) efree(key);
+ 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 &&
@@ -2280,7 +2280,7 @@ cluster_cmd_get_slot(redisCluster *c, zval *z_arg TSRMLS_DC)
(unsigned short)Z_LVAL_P(z_port));
/* Inform the caller if they've passed bad data */
- if(slot < 0) {
+ if (slot < 0) {
php_error_docref(0 TSRMLS_CC, E_WARNING, "Unknown node %s:%ld",
Z_STRVAL_P(z_host), Z_LVAL_P(z_port));
}
@@ -2305,14 +2305,14 @@ cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
zval *z_arg;
short slot;
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_arg)==FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_arg) == FAILURE) {
RETURN_FALSE;
}
// One argument means find the node (treated like a key), and two means
// send the command to a specific host and port
slot = cluster_cmd_get_slot(c, z_arg TSRMLS_CC);
- if(slot<0) {
+ if (slot < 0) {
RETURN_FALSE;
}
@@ -2320,7 +2320,7 @@ cluster_empty_node_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw,
cmd_len = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, kw, "");
// Kick off our command
- if(cluster_send_slot(c, slot, cmd, cmd_len, reply_type TSRMLS_CC)<0) {
+ if (cluster_send_slot(c, slot, cmd, cmd_len, reply_type TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Unable to send command at a specific node", 0 TSRMLS_CC);
efree(cmd);
@@ -2346,14 +2346,14 @@ static void cluster_raw_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len)
int i, argc = ZEND_NUM_ARGS();
/* Commands using this pass-thru don't need to be enabled in MULTI mode */
- if(!CLUSTER_IS_ATOMIC(c)) {
+ if (!CLUSTER_IS_ATOMIC(c)) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"Command can't be issued in MULTI mode");
RETURN_FALSE;
}
/* We at least need the key or [host,port] argument */
- if(argc<1) {
+ if (argc<1) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"Command requires at least an argument to direct to a node");
RETURN_FALSE;
@@ -2369,7 +2369,7 @@ static void cluster_raw_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len)
}
/* First argument needs to be the "where" */
- if((slot = cluster_cmd_get_slot(c, &z_args[0] TSRMLS_CC))<0) {
+ if ((slot = cluster_cmd_get_slot(c, &z_args[0] TSRMLS_CC)) < 0) {
efree(z_args);
RETURN_FALSE;
}
@@ -2378,14 +2378,14 @@ static void cluster_raw_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, int kw_len)
redis_cmd_init_sstr(&cmd, argc-1, kw, kw_len);
/* Iterate, appending args */
- for(i=1;i<argc;i++) {
+ for(i = 1; i < argc; i++) {
zend_string *zstr = zval_get_string(&z_args[i]);
redis_cmd_append_sstr(&cmd, ZSTR_VAL(zstr), ZSTR_LEN(zstr));
zend_string_release(zstr);
}
/* Send it off */
- if(cluster_send_slot(c, slot, cmd.c, cmd.len, TYPE_EOF TSRMLS_CC)<0) {
+ if (cluster_send_slot(c, slot, cmd.c, cmd.len, TYPE_EOF TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't send command to node", 0 TSRMLS_CC);
efree(cmd.c);
@@ -2405,9 +2405,9 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
REDIS_SCAN_TYPE type)
{
redisCluster *c = GET_CONTEXT();
- char *cmd, *pat=NULL, *key=NULL;
+ char *cmd, *pat = NULL, *key = NULL;
strlen_t key_len = 0, pat_len = 0;
- int cmd_len, key_free=0;
+ int cmd_len, key_free = 0;
short slot;
zval *z_it;
HashTable *hash;
@@ -2415,15 +2415,15 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
zend_long count = 0;
// Can't be in MULTI mode
- if(!CLUSTER_IS_ATOMIC(c)) {
+ if (!CLUSTER_IS_ATOMIC(c)) {
zend_throw_exception(redis_cluster_exception_ce,
"SCAN type commands can't be called in MULTI mode!", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* Parse arguments */
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|s!l", &key,
- &key_len, &z_it, &pat, &pat_len, &count)==FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/|s!l", &key,
+ &key_len, &z_it, &pat, &pat_len, &count) == FAILURE)
{
RETURN_FALSE;
}
@@ -2433,10 +2433,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
// Convert iterator to long if it isn't, update our long iterator if it's
// set and >0, and finish if it's back to zero
- if(Z_TYPE_P(z_it) != IS_LONG || Z_LVAL_P(z_it)<0) {
+ if (Z_TYPE_P(z_it) != IS_LONG || Z_LVAL_P(z_it) < 0) {
convert_to_long(z_it);
it = 0;
- } else if(Z_LVAL_P(z_it)!=0) {
+ } else if (Z_LVAL_P(z_it) != 0) {
it = Z_LVAL_P(z_it);
} else {
RETURN_FALSE;
@@ -2460,22 +2460,22 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
count);
// Send it off
- if(cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC)==FAILURE)
+ if (cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC) == FAILURE)
{
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't send SCAN command", 0 TSRMLS_CC);
- if(key_free) efree(key);
+ if (key_free) efree(key);
efree(cmd);
RETURN_FALSE;
}
// Read response
- if(cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, type,
- &it)==FAILURE)
+ if (cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, type,
+ &it) == FAILURE)
{
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't read SCAN response", 0 TSRMLS_CC);
- if(key_free) efree(key);
+ if (key_free) efree(key);
efree(cmd);
RETURN_FALSE;
}
@@ -2486,10 +2486,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
// Free our command
efree(cmd);
- } while(c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+ } while (c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
// Free our key
- if(key_free) efree(key);
+ if (key_free) efree(key);
// Update iterator reference
Z_LVAL_P(z_it) = it;
@@ -2498,7 +2498,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
/* {{{ proto RedisCluster::scan(string master, long it [, string pat, long cnt]) */
PHP_METHOD(RedisCluster, scan) {
redisCluster *c = GET_CONTEXT();
- char *cmd, *pat=NULL;
+ char *cmd, *pat = NULL;
strlen_t pat_len = 0;
int cmd_len;
short slot;
@@ -2510,24 +2510,24 @@ PHP_METHOD(RedisCluster, scan) {
c->readonly = CLUSTER_IS_ATOMIC(c);
/* Can't be in MULTI mode */
- if(!CLUSTER_IS_ATOMIC(c)) {
+ if (!CLUSTER_IS_ATOMIC(c)) {
zend_throw_exception(redis_cluster_exception_ce,
"SCAN type commands can't be called in MULTI mode", 0 TSRMLS_CC);
RETURN_FALSE;
}
/* Parse arguments */
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z|s!l", &z_it,
- &z_node, &pat, &pat_len, &count)==FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/z|s!l", &z_it,
+ &z_node, &pat, &pat_len, &count) == FAILURE)
{
RETURN_FALSE;
}
/* Convert or update iterator */
- if(Z_TYPE_P(z_it) != IS_LONG || Z_LVAL_P(z_it)<0) {
+ if (Z_TYPE_P(z_it) != IS_LONG || Z_LVAL_P(z_it) < 0) {
convert_to_long(z_it);
it = 0;
- } else if(Z_LVAL_P(z_it)!=0) {
+ } else if (Z_LVAL_P(z_it) != 0) {
it = Z_LVAL_P(z_it);
} else {
RETURN_FALSE;
@@ -2546,12 +2546,12 @@ PHP_METHOD(RedisCluster, scan) {
cmd_len = redis_fmt_scan_cmd(&cmd, TYPE_SCAN, NULL, 0, it, pat, pat_len,
count);
- if((slot = cluster_cmd_get_slot(c, z_node TSRMLS_CC))<0) {
+ if ((slot = cluster_cmd_get_slot(c, z_node TSRMLS_CC)) < 0) {
RETURN_FALSE;
}
// Send it to the node in question
- if(cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC)<0)
+ if (cluster_send_command(c, slot, cmd, cmd_len TSRMLS_CC) < 0)
{
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't send SCAN to node", 0 TSRMLS_CC);
@@ -2559,8 +2559,8 @@ PHP_METHOD(RedisCluster, scan) {
RETURN_FALSE;
}
- if(cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, TYPE_SCAN,
- &it)==FAILURE || Z_TYPE_P(return_value)!=IS_ARRAY)
+ if (cluster_scan_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, TYPE_SCAN,
+ &it) == FAILURE || Z_TYPE_P(return_value)!=IS_ARRAY)
{
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't process SCAN response from node", 0 TSRMLS_CC);
@@ -2571,7 +2571,7 @@ PHP_METHOD(RedisCluster, scan) {
efree(cmd);
num_ele = zend_hash_num_elements(Z_ARRVAL_P(return_value));
- } while(c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
+ } while (c->flags->scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0);
Z_LVAL_P(z_it) = it;
}
@@ -2656,15 +2656,15 @@ PHP_METHOD(RedisCluster, lastsave) {
PHP_METHOD(RedisCluster, info) {
redisCluster *c = GET_CONTEXT();
REDIS_REPLY_TYPE rtype;
- char *cmd, *opt=NULL;
+ char *cmd, *opt = NULL;
int cmd_len;
strlen_t opt_len = 0;
void *ctx = NULL;
zval *z_arg;
short slot;
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &z_arg, &opt,
- &opt_len)==FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|s", &z_arg, &opt,
+ &opt_len) == FAILURE)
{
RETURN_FALSE;
}
@@ -2684,7 +2684,7 @@ PHP_METHOD(RedisCluster, info) {
}
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_BULK : TYPE_LINE;
- if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC)<0) {
+ if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Unable to send INFO command to specific node", 0 TSRMLS_CC);
efree(cmd);
@@ -2708,7 +2708,7 @@ PHP_METHOD(RedisCluster, info) {
*/
PHP_METHOD(RedisCluster, client) {
redisCluster *c = GET_CONTEXT();
- char *cmd, *opt=NULL, *arg=NULL;
+ char *cmd, *opt = NULL, *arg = NULL;
int cmd_len;
strlen_t opt_len, arg_len = 0;
REDIS_REPLY_TYPE rtype;
@@ -2718,14 +2718,14 @@ PHP_METHOD(RedisCluster, client) {
/* Parse args */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs|s", &z_node, &opt,
- &opt_len, &arg, &arg_len)==FAILURE)
+ &opt_len, &arg, &arg_len) == FAILURE)
{
RETURN_FALSE;
}
/* Make sure we can properly resolve the slot */
slot = cluster_cmd_get_slot(c, z_node TSRMLS_CC);
- if(slot<0) RETURN_FALSE;
+ if (slot < 0) RETURN_FALSE;
/* Our return type and reply callback is different for all subcommands */
if (opt_len == 4 && !strncasecmp(opt, "list", 4)) {
@@ -2749,7 +2749,7 @@ PHP_METHOD(RedisCluster, client) {
if (ZEND_NUM_ARGS() == 3) {
cmd_len = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, "CLIENT", "ss",
opt, opt_len, arg, arg_len);
- } else if(ZEND_NUM_ARGS() == 2) {
+ } else if (ZEND_NUM_ARGS() == 2) {
cmd_len = redis_spprintf(NULL, NULL TSRMLS_CC, &cmd, "CLIENT", "s",
opt, opt_len);
} else {
@@ -2758,7 +2758,7 @@ PHP_METHOD(RedisCluster, client) {
}
/* Attempt to write our command */
- if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC)<0) {
+ if (cluster_send_slot(c, slot, cmd, cmd_len, rtype TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Unable to send CLIENT command to specific node", 0 TSRMLS_CC);
efree(cmd);
@@ -2933,8 +2933,8 @@ PHP_METHOD(RedisCluster, echo) {
strlen_t msg_len;
short slot;
- if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_arg, &msg,
- &msg_len)==FAILURE)
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &z_arg, &msg,
+ &msg_len) == FAILURE)
{
RETURN_FALSE;
}
@@ -2944,7 +2944,7 @@ PHP_METHOD(RedisCluster, echo) {
/* Grab slot either by key or host/port */
slot = cluster_cmd_get_slot(c, z_arg TSRMLS_CC);
- if(slot<0) {
+ if (slot < 0) {
RETURN_FALSE;
}
@@ -2953,7 +2953,7 @@ PHP_METHOD(RedisCluster, echo) {
/* Send it off */
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_BULK : TYPE_LINE;
- if(cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC)<0) {
+ if (cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Unable to send commnad at the specificed node", 0 TSRMLS_CC);
efree(cmd);
@@ -2995,7 +2995,7 @@ PHP_METHOD(RedisCluster, rawcommand) {
efree(z_args);
RETURN_FALSE;
} else if (redis_build_raw_cmd(&z_args[1], argc-1, &cmd, &cmd_len TSRMLS_CC) ||
- (slot = cluster_cmd_get_slot(c, &z_args[0] TSRMLS_CC))<0)
+ (slot = cluster_cmd_get_slot(c, &z_args[0] TSRMLS_CC)) < 0)
{
if (cmd) efree(cmd);
efree(z_args);
@@ -3007,7 +3007,7 @@ PHP_METHOD(RedisCluster, rawcommand) {
/* Direct the command */
rtype = CLUSTER_IS_ATOMIC(c) ? TYPE_EOF : TYPE_LINE;
- if (cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC)<0) {
+ if (cluster_send_slot(c,slot,cmd,cmd_len,rtype TSRMLS_CC) < 0) {
zend_throw_exception(redis_cluster_exception_ce,
"Unable to send command to the specified node", 0 TSRMLS_CC);
efree(cmd);