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 /cluster_library.c
parent78fa97684ee85f4848ba78e07527deb6caff2fe2 (diff)
Some style normalization
Diffstat (limited to 'cluster_library.c')
-rw-r--r--cluster_library.c304
1 files changed, 152 insertions, 152 deletions
diff --git a/cluster_library.c b/cluster_library.c
index 0a3adf2d..2a44bb2d 100644
--- a/cluster_library.c
+++ b/cluster_library.c
@@ -60,10 +60,10 @@ static void dump_reply(clusterReply *reply, int indent) {
smart_string_appendl(&buf, "\"", 1);
break;
case TYPE_MULTIBULK:
- if(reply->elements == (size_t)-1) {
+ if (reply->elements == (size_t)-1) {
smart_string_appendl(&buf, "(nil)", sizeof("(nil)")-1);
} else {
- for(i=0;i<reply->elements;i++) {
+ for (i = 0; i < reply->elements; i++) {
dump_reply(reply->element[i], indent+2);
}
}
@@ -72,8 +72,8 @@ static void dump_reply(clusterReply *reply, int indent) {
break;
}
- if(buf.len > 0) {
- for(i=0;i<indent;i++) {
+ if (buf.len > 0) {
+ for (i = 0; i < indent; i++) {
php_printf(" ");
}
@@ -96,11 +96,11 @@ void cluster_free_reply(clusterReply *reply, int free_data) {
case TYPE_ERR:
case TYPE_LINE:
case TYPE_BULK:
- if(free_data && reply->str)
+ if (free_data && reply->str)
efree(reply->str);
break;
case TYPE_MULTIBULK:
- for(i=0;i<reply->elements && reply->element[i]; i++) {
+ for (i = 0; i < reply->elements && reply->element[i]; i++) {
cluster_free_reply(reply->element[i], free_data);
}
efree(reply->element);
@@ -125,7 +125,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
r = element[i] = ecalloc(1, sizeof(clusterReply));
// Bomb out, flag error condition on a communication failure
- if(redis_read_reply_type(sock, &r->type, &len TSRMLS_CC)<0) {
+ if (redis_read_reply_type(sock, &r->type, &len TSRMLS_CC) < 0) {
*err = 1;
return;
}
@@ -136,7 +136,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
switch(r->type) {
case TYPE_ERR:
case TYPE_LINE:
- if(redis_sock_gets(sock,buf,sizeof(buf),&sz TSRMLS_CC)<0) {
+ if (redis_sock_gets(sock,buf,sizeof(buf),&sz TSRMLS_CC) < 0) {
*err = 1;
return;
}
@@ -148,7 +148,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
case TYPE_BULK:
if (r->len > 0) {
r->str = redis_sock_read_bulk_reply(sock,r->len TSRMLS_CC);
- if(!r->str) {
+ if (!r->str) {
*err = 1;
return;
}
@@ -159,7 +159,7 @@ cluster_multibulk_resp_recursive(RedisSock *sock, size_t elements,
r->elements = r->len;
cluster_multibulk_resp_recursive(sock, r->elements, r->element,
err TSRMLS_CC);
- if(*err) return;
+ if (*err) return;
break;
default:
*err = 1;
@@ -219,14 +219,14 @@ cluster_read_sock_resp(RedisSock *redis_sock, REDIS_REPLY_TYPE type,
case TYPE_BULK:
r->len = len;
r->str = redis_sock_read_bulk_reply(redis_sock, len TSRMLS_CC);
- if(r->len != -1 && !r->str) {
+ if (r->len != -1 && !r->str) {
cluster_free_reply(r, 1);
return NULL;
}
break;
case TYPE_MULTIBULK:
r->elements = len;
- if(len != (size_t)-1) {
+ if (len != (size_t)-1) {
r->element = ecalloc(len, sizeof(clusterReply*)*len);
cluster_multibulk_resp_recursive(redis_sock, len, r->element,
&err TSRMLS_CC);
@@ -238,7 +238,7 @@ cluster_read_sock_resp(RedisSock *redis_sock, REDIS_REPLY_TYPE type,
}
// Free/return null on communication error
- if(err) {
+ if (err) {
cluster_free_reply(r,1);
return NULL;
}
@@ -286,7 +286,7 @@ static int cluster_send_readonly(RedisSock *redis_sock TSRMLS_DC) {
/* Return success if we can send it */
ret = cluster_send_direct(redis_sock, RESP_READONLY_CMD,
- sizeof(RESP_READONLY_CMD)-1, TYPE_LINE TSRMLS_CC);
+ sizeof(RESP_READONLY_CMD) - 1, TYPE_LINE TSRMLS_CC);
/* Flag this socket as READONLY if our command worked */
redis_sock->readonly = !ret;
@@ -298,7 +298,7 @@ static int cluster_send_readonly(RedisSock *redis_sock TSRMLS_DC) {
/* Send MULTI to a specific ReidsSock */
static int cluster_send_multi(redisCluster *c, short slot TSRMLS_DC) {
if (cluster_send_direct(SLOT_SOCK(c,slot), RESP_MULTI_CMD,
- sizeof(RESP_MULTI_CMD)-1, TYPE_LINE TSRMLS_CC)==0)
+ sizeof(RESP_MULTI_CMD) - 1, TYPE_LINE TSRMLS_CC) == 0)
{
c->cmd_sock->mode = MULTI;
return 0;
@@ -350,10 +350,10 @@ static void cluster_dist_free_ht(zval *p)
clusterDistList *dl = *(clusterDistList**)p;
int i;
- for(i=0; i < dl->len; i++) {
- if(dl->entry[i].key_free)
+ for (i = 0; i < dl->len; i++) {
+ if (dl->entry[i].key_free)
efree(dl->entry[i].key);
- if(dl->entry[i].val_free)
+ if (dl->entry[i].val_free)
efree(dl->entry[i].val);
}
@@ -394,7 +394,7 @@ static clusterKeyVal *cluster_dl_add_key(clusterDistList *dl, char *key,
int key_len, int key_free)
{
// Reallocate if required
- if(dl->len==dl->size) {
+ if (dl->len == dl->size) {
dl->entry = erealloc(dl->entry, sizeof(clusterKeyVal) * dl->size * 2);
dl->size *= 2;
}
@@ -427,8 +427,8 @@ int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key,
slot = cluster_hash_key(key, key_len);
// We can't do this if we don't fully understand the keyspace
- if(c->master[slot] == NULL) {
- if(key_free) efree(key);
+ if (c->master[slot] == NULL) {
+ if (key_free) efree(key);
return FAILURE;
}
@@ -442,7 +442,7 @@ int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key,
retptr = cluster_dl_add_key(dl, key, key_len, key_free);
// Push our return pointer if requested
- if(kv) *kv = retptr;
+ if (kv) *kv = retptr;
return SUCCESS;
}
@@ -509,7 +509,7 @@ static void ht_free_slave(void *data)
static void ht_free_slave(zval *data)
#endif
{
- if(*(redisClusterNode**)data) {
+ if (*(redisClusterNode**)data) {
cluster_free_node(*(redisClusterNode**)data);
}
}
@@ -519,20 +519,20 @@ unsigned short cluster_hash_key(const char *key, int len) {
int s, e;
// Find first occurrence of {, if any
- for(s=0;s<len;s++) {
- if(key[s]=='{') break;
+ for (s = 0; s < len; s++) {
+ if (key[s]=='{') break;
}
// There is no '{', hash everything
- if(s == len) return crc16(key, len) & REDIS_CLUSTER_MOD;
+ if (s == len) return crc16(key, len) & REDIS_CLUSTER_MOD;
// Found it, look for a tailing '}'
- for(e=s+1;e<len;e++) {
- if(key[e]=='}') break;
+ for (e =s + 1; e < len; e++) {
+ if (key[e] == '}') break;
}
// Hash the whole key if we don't find a tailing } or if {} is empty
- if(e == len || e == s+1) return crc16(key, len) & REDIS_CLUSTER_MOD;
+ if (e == len || e == s+1) return crc16(key, len) & REDIS_CLUSTER_MOD;
// Hash just the bit betweeen { and }
return crc16((char*)key+s+1,e-s-1) & REDIS_CLUSTER_MOD;
@@ -610,18 +610,18 @@ clusterReply* cluster_get_slots(RedisSock *redis_sock TSRMLS_DC)
long len;
// Send the command to the socket and consume reply type
- if(redis_sock_write(redis_sock, RESP_CLUSTER_SLOTS_CMD,
- sizeof(RESP_CLUSTER_SLOTS_CMD)-1 TSRMLS_CC)<0 ||
- redis_read_reply_type(redis_sock, &type, &len TSRMLS_CC)<0)
+ if (redis_sock_write(redis_sock, RESP_CLUSTER_SLOTS_CMD,
+ sizeof(RESP_CLUSTER_SLOTS_CMD)-1 TSRMLS_CC) < 0 ||
+ redis_read_reply_type(redis_sock, &type, &len TSRMLS_CC) < 0)
{
return NULL;
}
// Consume the rest of our response
- if((r = cluster_read_sock_resp(redis_sock, type, len TSRMLS_CC))==NULL ||
+ if ((r = cluster_read_sock_resp(redis_sock, type, len TSRMLS_CC)) == NULL ||
r->type != TYPE_MULTIBULK || r->elements < 1)
{
- if(r) cluster_free_reply(r, 1);
+ if (r) cluster_free_reply(r, 1);
return NULL;
}
@@ -655,7 +655,7 @@ cluster_node_add_slave(redisClusterNode *master, redisClusterNode *slave)
ulong index;
// Allocate our slaves hash table if we haven't yet
- if(!master->slaves) {
+ if (!master->slaves) {
ALLOC_HASHTABLE(master->slaves);
zend_hash_init(master->slaves, 0, NULL, ht_free_slave, 0);
index = 1;
@@ -668,11 +668,11 @@ cluster_node_add_slave(redisClusterNode *master, redisClusterNode *slave)
/* Sanity check/validation for CLUSTER SLOTS command */
#define VALIDATE_SLOTS_OUTER(r) \
- (r->elements>=3 && r2->element[0]->type == TYPE_INT && \
- r->element[1]->type==TYPE_INT)
+ (r->elements >= 3 && r2->element[0]->type == TYPE_INT && \
+ r->element[1]->type == TYPE_INT)
#define VALIDATE_SLOTS_INNER(r) \
- (r->type == TYPE_MULTIBULK && r->elements>=2 && \
- r->element[0]->type == TYPE_BULK && r->element[1]->type==TYPE_INT)
+ (r->type == TYPE_MULTIBULK && r->elements >= 2 && \
+ r->element[0]->type == TYPE_BULK && r->element[1]->type == TYPE_INT)
/* Use the output of CLUSTER SLOTS to map our nodes */
static int cluster_map_slots(redisCluster *c, clusterReply *r) {
@@ -683,12 +683,12 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) {
unsigned short port;
char *host, key[1024];
- for(i=0;i<r->elements;i++) {
+ for (i = 0; i < r->elements; i++) {
// Inner response
r2 = r->element[i];
// Validate outer and master slot
- if(!VALIDATE_SLOTS_OUTER(r2) || !VALIDATE_SLOTS_INNER(r2->element[2])) {
+ if (!VALIDATE_SLOTS_OUTER(r2) || !VALIDATE_SLOTS_INNER(r2->element[2])) {
return -1;
}
@@ -712,14 +712,14 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) {
}
// Attach slaves
- for(j=3;j<r2->elements;j++) {
+ for (j = 3; j< r2->elements; j++) {
r3 = r2->element[j];
- if(!VALIDATE_SLOTS_INNER(r3)) {
+ if (!VALIDATE_SLOTS_INNER(r3)) {
return -1;
}
// Skip slaves where the host is ""
- if(r3->element[0]->len == 0) continue;
+ if (r3->element[0]->len == 0) continue;
// Attach this node to our slave
slave = cluster_node_create(c, r3->element[0]->str,
@@ -729,8 +729,8 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) {
}
// Attach this node to each slot in the range
- for(j=low;j<=high;j++) {
- c->master[j]=master;
+ for (j = low; j<= high; j++) {
+ c->master[j] = master;
}
}
@@ -740,7 +740,7 @@ static int cluster_map_slots(redisCluster *c, clusterReply *r) {
/* Free a redisClusterNode structure */
PHP_REDIS_API void cluster_free_node(redisClusterNode *node) {
- if(node->slaves) {
+ if (node->slaves) {
zend_hash_destroy(node->slaves);
efree(node->slaves);
}
@@ -784,7 +784,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 */
@@ -855,7 +855,7 @@ PHP_REDIS_API void cluster_free(redisCluster *c) {
* which have been randomized. The return value needs to be freed. */
static zval **cluster_shuffle_seeds(HashTable *seeds, int *len) {
zval **z_seeds, *z_ele;
- int *map, i, count, index=0;
+ int *map, i, count, index = 0;
/* How many */
count = zend_hash_num_elements(seeds);
@@ -928,8 +928,8 @@ cluster_init_seeds(redisCluster *cluster, HashTable *ht_seeds) {
/* Initial mapping of our cluster keyspace */
PHP_REDIS_API int cluster_map_keyspace(redisCluster *c TSRMLS_DC) {
RedisSock *seed;
- clusterReply *slots=NULL;
- int mapped=0;
+ clusterReply *slots = NULL;
+ int mapped = 0;
// Iterate over seeds until we can get slots
ZEND_HASH_FOREACH_PTR(c->seeds, seed) {
@@ -952,10 +952,10 @@ PHP_REDIS_API int cluster_map_keyspace(redisCluster *c TSRMLS_DC) {
} ZEND_HASH_FOREACH_END();
// Clean up slots reply if we got one
- if(slots) cluster_free_reply(slots, 1);
+ if (slots) cluster_free_reply(slots, 1);
// Throw an exception if we couldn't map
- if(!mapped) {
+ if (!mapped) {
zend_throw_exception(redis_cluster_exception_ce,
"Couldn't map cluster keyspace using any provided seed", 0
TSRMLS_CC);
@@ -1013,26 +1013,26 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type
CLUSTER_CLEAR_ERROR(c);
CLUSTER_CLEAR_REPLY(c);
- if(-1 == redis_check_eof(c->cmd_sock, 1 TSRMLS_CC) ||
+ if (-1 == redis_check_eof(c->cmd_sock, 1 TSRMLS_CC) ||
EOF == (*reply_type = php_stream_getc(c->cmd_sock->stream)))
{
return -1;
}
// In the event of an ERROR, check if it's a MOVED/ASK error
- if(*reply_type == TYPE_ERR) {
+ if (*reply_type == TYPE_ERR) {
char inbuf[4096];
int moved;
// Attempt to read the error
- if(!php_stream_gets(c->cmd_sock->stream, inbuf, sizeof(inbuf))) {
+ if (!php_stream_gets(c->cmd_sock->stream, inbuf, sizeof(inbuf))) {
return -1;
}
// Check for MOVED or ASK redirection
- if((moved = IS_MOVED(inbuf)) || IS_ASK(inbuf)) {
+ if ((moved = IS_MOVED(inbuf)) || IS_ASK(inbuf)) {
// Set our redirection information
- if(cluster_set_redirection(c,inbuf,moved)<0) {
+ if (cluster_set_redirection(c,inbuf,moved) < 0) {
return -1;
}
@@ -1046,14 +1046,14 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type
}
// Fetch the first line of our response from Redis.
- if(redis_sock_gets(c->cmd_sock,c->line_reply,sizeof(c->line_reply),
- &sz TSRMLS_CC)<0)
+ if (redis_sock_gets(c->cmd_sock,c->line_reply,sizeof(c->line_reply),
+ &sz TSRMLS_CC) < 0)
{
return -1;
}
// For replies that will give us a numberic length, convert it
- if(*reply_type != TYPE_LINE) {
+ if (*reply_type != TYPE_LINE) {
c->reply_len = strtol(c->line_reply, NULL, 10);
} else {
c->reply_len = (long long)sz;
@@ -1080,7 +1080,7 @@ PHP_REDIS_API void cluster_disconnect(redisCluster *c TSRMLS_DC) {
static int cluster_dist_write(redisCluster *c, const char *cmd, size_t sz,
int nomaster TSRMLS_DC)
{
- int i, count=1, *nodes;
+ int i, count = 1, *nodes;
RedisSock *redis_sock;
/* Determine our overall node count */
@@ -1169,9 +1169,9 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
/* If in ASK redirection, get/create the node for that host:port, otherwise
* just use the command socket. */
- if(c->redir_type == REDIR_ASK) {
+ if (c->redir_type == REDIR_ASK) {
redis_sock = cluster_get_asking_sock(c TSRMLS_CC);
- if(cluster_send_asking(redis_sock TSRMLS_CC)<0) {
+ if (cluster_send_asking(redis_sock TSRMLS_CC) < 0) {
return -1;
}
}
@@ -1201,7 +1201,7 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
}
/* Don't fall back if direct communication with this slot is required. */
- if(direct) return -1;
+ if (direct) return -1;
/* Fall back by attempting the request against every known node */
ZEND_HASH_FOREACH_PTR(c->nodes, seed_node) {
@@ -1243,16 +1243,16 @@ static void cluster_update_slot(redisCluster *c TSRMLS_DC) {
size_t klen;
/* Do we already have the new slot mapped */
- if(c->master[c->redir_slot]) {
+ if (c->master[c->redir_slot]) {
/* No need to do anything if it's the same node */
- if(!CLUSTER_REDIR_CMP(c)) {
+ if (!CLUSTER_REDIR_CMP(c)) {
return;
}
/* Check to see if we have this new node mapped */
node = cluster_find_node(c, c->redir_host, c->redir_port);
- if(node) {
+ if (node) {
/* Just point to this slot */
c->master[c->redir_slot] = node;
} else {
@@ -1270,7 +1270,7 @@ static void cluster_update_slot(redisCluster *c TSRMLS_DC) {
} else {
/* Check to see if the ip and port are mapped */
node = cluster_find_node(c, c->redir_host, c->redir_port);
- if(!node) {
+ if (!node) {
node = cluster_node_create(c, c->redir_host, c->redir_host_len,
c->redir_port, c->redir_slot, 0);
}
@@ -1294,9 +1294,9 @@ PHP_REDIS_API int cluster_abort_exec(redisCluster *c TSRMLS_DC) {
clusterFoldItem *fi = c->multi_head;
/* Loop through our fold items */
- while(fi) {
- if(SLOT_SOCK(c,fi->slot)->mode == MULTI) {
- if(cluster_send_discard(c, fi->slot TSRMLS_CC)<0) {
+ while (fi) {
+ if (SLOT_SOCK(c,fi->slot)->mode == MULTI) {
+ if (cluster_send_discard(c, fi->slot TSRMLS_CC) < 0) {
cluster_disconnect(c TSRMLS_CC);
return -1;
}
@@ -1321,8 +1321,8 @@ PHP_REDIS_API short cluster_find_slot(redisCluster *c, const char *host,
{
int i;
- for(i=0;i<REDIS_CLUSTER_SLOTS;i++) {
- if(c->master[i] && c->master[i]->sock &&
+ for (i = 0; i < REDIS_CLUSTER_SLOTS; i++) {
+ if (c->master[i] && c->master[i]->sock &&
c->master[i]->sock->port == port &&
!strcasecmp(ZSTR_VAL(c->master[i]->sock->host), host))
{
@@ -1354,12 +1354,12 @@ PHP_REDIS_API int cluster_send_slot(redisCluster *c, short slot, char *cmd,
}
/* Try the slot */
- if(cluster_sock_write(c, cmd, cmd_len, 1 TSRMLS_CC)==-1) {
+ if (cluster_sock_write(c, cmd, cmd_len, 1 TSRMLS_CC) == -1) {
return -1;
}
/* Check our response */
- if(cluster_check_response(c, &c->reply_type TSRMLS_CC)!=0 ||
+ if (cluster_check_response(c, &c->reply_type TSRMLS_CC) != 0 ||
(rtype != TYPE_EOF && rtype != c->reply_type)) return -1;
/* Success */
@@ -1371,7 +1371,7 @@ PHP_REDIS_API int cluster_send_slot(redisCluster *c, short slot, char *cmd,
PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char *cmd,
int cmd_len TSRMLS_DC)
{
- int resp, timedout=0;
+ int resp, timedout = 0;
long msstart;
/* Set the slot we're operating against as well as it's socket. These can
@@ -1431,10 +1431,10 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
/* Figure out if we've timed out trying to read or write the data */
timedout = resp && c->waitms ? mstime() - msstart >= c->waitms : 0;
- } while(resp != 0 && !c->clusterdown && !timedout);
+ } while (resp != 0 && !c->clusterdown && !timedout);
// If we've detected the cluster is down, throw an exception
- if(c->clusterdown) {
+ if (c->clusterdown) {
zend_throw_exception(redis_cluster_exception_ce,
"The Redis Cluster is down (CLUSTERDOWN)", 0 TSRMLS_CC);
return -1;
@@ -1465,10 +1465,10 @@ PHP_REDIS_API void cluster_bulk_raw_resp(INTERNAL_FUNCTION_PARAMETERS,
char *resp;
// Make sure we can read the response
- if(c->reply_type != TYPE_BULK ||
- (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC))==NULL)
+ if (c->reply_type != TYPE_BULK ||
+ (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC)) == NULL)
{
- if(c->flags->mode != MULTI) {
+ if (c->flags->mode != MULTI) {
RETURN_FALSE;
} else {
add_next_index_bool(&c->multi_resp, 0);
@@ -1488,8 +1488,8 @@ PHP_REDIS_API void cluster_bulk_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
char *resp;
// Make sure we can read the response
- if(c->reply_type != TYPE_BULK ||
- (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC))==NULL)
+ if (c->reply_type != TYPE_BULK ||
+ (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC)) == NULL)
{
CLUSTER_RETURN_FALSE(c);
}
@@ -1521,8 +1521,8 @@ PHP_REDIS_API void cluster_dbl_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
double dbl;
// Make sure we can read the response
- if(c->reply_type != TYPE_BULK ||
- (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC))==NULL)
+ if (c->reply_type != TYPE_BULK ||
+ (resp = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC)) == NULL)
{
CLUSTER_RETURN_FALSE(c);
}
@@ -1540,7 +1540,7 @@ PHP_REDIS_API void cluster_bool_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
void *ctx)
{
// Check that we have +OK
- if(c->reply_type != TYPE_LINE || c->reply_len != 2 ||
+ if (c->reply_type != TYPE_LINE || c->reply_len != 2 ||
c->line_reply[0] != 'O' || c->line_reply[1] != 'K')
{
CLUSTER_RETURN_FALSE(c);
@@ -1553,7 +1553,7 @@ PHP_REDIS_API void cluster_bool_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
PHP_REDIS_API void cluster_ping_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
void *ctx)
{
- if(c->reply_type != TYPE_LINE || c->reply_len != 4 ||
+ if (c->reply_type != TYPE_LINE || c->reply_len != 4 ||
memcmp(c->line_reply,"PONG",sizeof("PONG")-1))
{
CLUSTER_RETURN_FALSE(c);
@@ -1567,7 +1567,7 @@ PHP_REDIS_API void cluster_1_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
void *ctx)
{
// Validate our reply type, and check for a zero
- if(c->reply_type != TYPE_INT || c->reply_len == 0) {
+ if (c->reply_type != TYPE_INT || c->reply_len == 0) {
CLUSTER_RETURN_FALSE(c);
}
@@ -1578,7 +1578,7 @@ PHP_REDIS_API void cluster_1_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
PHP_REDIS_API void cluster_long_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
void *ctx)
{
- if(c->reply_type != TYPE_INT) {
+ if (c->reply_type != TYPE_INT) {
CLUSTER_RETURN_FALSE(c);
}
CLUSTER_RETURN_LONG(c, c->reply_len);
@@ -1589,20 +1589,20 @@ PHP_REDIS_API void cluster_type_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
void *ctx)
{
// Make sure we got the right kind of response
- if(c->reply_type != TYPE_LINE) {
+ if (c->reply_type != TYPE_LINE) {
CLUSTER_RETURN_FALSE(c);
}
// Switch on the type
- if(strncmp (c->line_reply, "string", 6)==0) {
+ if (strncmp (c->line_reply, "string", 6) == 0) {
CLUSTER_RETURN_LONG(c, REDIS_STRING);
- } else if (strncmp(c->line_reply, "set", 3)==0) {
+ } else if (strncmp(c->line_reply, "set", 3) == 0) {
CLUSTER_RETURN_LONG(c, REDIS_SET);
- } else if (strncmp(c->line_reply, "list", 4)==0) {
+ } else if (strncmp(c->line_reply, "list", 4) == 0) {
CLUSTER_RETURN_LONG(c, REDIS_LIST);
- } else if (strncmp(c->line_reply, "hash", 4)==0) {
+ } else if (strncmp(c->line_reply, "hash", 4) == 0) {
CLUSTER_RETURN_LONG(c, REDIS_HASH);
- } else if (strncmp(c->line_reply, "zset", 4)==0) {
+ } else if (strncmp(c->line_reply, "zset", 4) == 0) {
CLUSTER_RETURN_LONG(c, REDIS_ZSET);
} else {
CLUSTER_RETURN_LONG(c, REDIS_NOT_FOUND);
@@ -1615,11 +1615,11 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
{
subscribeContext *sctx = (subscribeContext*)ctx;
zval z_tab, *z_tmp;
- int pull=0;
+ int pull = 0;
// Consume each MULTI BULK response (one per channel/pattern)
- while(sctx->argc--) {
+ while (sctx->argc--) {
if (!cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c,
pull, mbulk_resp_loop_raw, &z_tab)
) {
@@ -1654,10 +1654,10 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
c->subscribed_slot = c->cmd_slot;
/* Multibulk response, {[pattern], type, channel, payload} */
- while(1) {
+ while (1) {
/* Arguments */
zval *z_type, *z_chan, *z_pat = NULL, *z_data;
- int tab_idx=1, is_pmsg;
+ int tab_idx = 1, is_pmsg;
// Get the next subscribe response
if (!cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, 1, mbulk_resp_loop, &z_tab) ||
@@ -1692,7 +1692,7 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
z_args[0] = &getThis();
// Set up calbacks depending on type
- if(is_pmsg) {
+ if (is_pmsg) {
z_args[1] = &z_pat;
z_args[2] = &z_chan;
z_args[3] = &z_data;
@@ -1704,7 +1704,7 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
z_args[0] = *getThis();
// Set up calbacks depending on type
- if(is_pmsg) {
+ if (is_pmsg) {
z_args[1] = *z_pat;
z_args[2] = *z_chan;
z_args[3] = *z_data;
@@ -1718,7 +1718,7 @@ PHP_REDIS_API void cluster_sub_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
sctx->cb.param_count = tab_idx;
// Execute our callback
- if(zend_call_function(&(sctx->cb), &(sctx->cb_cache) TSRMLS_CC)!=
+ if (zend_call_function(&(sctx->cb), &(sctx->cb_cache) TSRMLS_CC) !=
SUCCESS)
{
break;
@@ -1753,7 +1753,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS,
array_init(return_value);
// Consume each response
- while(argc--) {
+ while (argc--) {
// Fail if we didn't get an array or can't find index 1
if (!cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, pull, mbulk_resp_loop_raw, &z_tab) ||
(z_chan = zend_hash_index_find(Z_ARRVAL(z_tab), 1)) == NULL
@@ -1776,7 +1776,7 @@ PHP_REDIS_API void cluster_unsub_resp(INTERNAL_FUNCTION_PARAMETERS,
char *flag = Z_STRVAL_P(z_flag);
// Add result
- add_assoc_bool(return_value, Z_STRVAL_P(z_chan), flag[1]=='1');
+ add_assoc_bool(return_value, Z_STRVAL_P(z_chan), flag[1] == '1');
zval_dtor(&z_tab);
pull = 1;
@@ -1809,7 +1809,7 @@ static void cluster_mbulk_variant_resp(clusterReply *r, zval *z_ret)
MAKE_STD_ZVAL(z_sub_ele);
#endif
array_init(z_sub_ele);
- for(i=0;i<r->elements;i++) {
+ for (i = 0; i < r->elements; i++) {
cluster_mbulk_variant_resp(r->element[i], z_sub_ele);
}
add_next_index_zval(z_ret, z_sub_ele);
@@ -1830,12 +1830,12 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
int i;
// Make sure we can read it
- if((r = cluster_read_resp(c TSRMLS_CC))==NULL) {
+ if ((r = cluster_read_resp(c TSRMLS_CC)) == NULL) {
CLUSTER_RETURN_FALSE(c);
}
// Handle ATOMIC vs. MULTI mode in a seperate switch
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
switch(r->type) {
case TYPE_INT:
RETVAL_LONG(r->integer);
@@ -1856,7 +1856,7 @@ PHP_REDIS_API void cluster_variant_resp(INTERNAL_FUNCTION_PARAMETERS, redisClust
case TYPE_MULTIBULK:
array_init(z_arr);
- for(i=0;i<r->elements;i++) {
+ for (i = 0; i < r->elements; i++) {
cluster_mbulk_variant_resp(r->element[i], z_arr);
}
RETVAL_ZVAL(z_arr, 1, 0);
@@ -1920,7 +1920,7 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
c->cmd_sock->serializer = c->flags->serializer;
/* Call our specified callback */
- if (cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC)==FAILURE) {
+ if (cb(c->cmd_sock, z_result, c->reply_len, ctx TSRMLS_CC) == FAILURE) {
zval_dtor(z_result);
#if (PHP_MAJOR_VERSION < 7)
efree(z_result);
@@ -1930,7 +1930,7 @@ PHP_REDIS_API void cluster_gen_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
}
// Success, make this array our return value
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
RETVAL_ZVAL(z_result, 0, 1);
} else {
add_next_index_zval(&c->multi_resp, z_result);
@@ -1944,20 +1944,20 @@ PHP_REDIS_API int cluster_scan_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
char *pit;
// We always want to see a MULTIBULK response with two elements
- if(c->reply_type != TYPE_MULTIBULK || c->reply_len != 2)
+ if (c->reply_type != TYPE_MULTIBULK || c->reply_len != 2)
{
return FAILURE;
}
// Read the BULK size
- if(cluster_check_response(c, &c->reply_type TSRMLS_CC),0 ||
+ if (cluster_check_response(c, &c->reply_type TSRMLS_CC),0 ||
c->reply_type != TYPE_BULK)
{
return FAILURE;
}
// Read the iterator
- if((pit = redis_sock_read_bulk_reply(c->cmd_sock,c->reply_len TSRMLS_CC))==NULL)
+ if ((pit = redis_sock_read_bulk_reply(c->cmd_sock,c->reply_len TSRMLS_CC)) == NULL)
{
return FAILURE;
}
@@ -1967,7 +1967,7 @@ PHP_REDIS_API int cluster_scan_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
efree(pit);
// We'll need another MULTIBULK response for the payload
- if(cluster_check_response(c, &c->reply_type TSRMLS_CC)<0)
+ if (cluster_check_response(c, &c->reply_type TSRMLS_CC) < 0)
{
return FAILURE;
}
@@ -2002,7 +2002,7 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
char *info;
// Read our bulk response
- if((info = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC))==NULL)
+ if ((info = redis_sock_read_bulk_reply(c->cmd_sock, c->reply_len TSRMLS_CC)) == NULL)
{
CLUSTER_RETURN_FALSE(c);
}
@@ -2012,7 +2012,7 @@ PHP_REDIS_API void cluster_info_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
efree(info);
// Return our array
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (CLUSTER_IS_ATOMIC(c)) {
RETVAL_ZVAL(z_result, 1, 0);
} else {
add_next_index_zval(&c->multi_resp, z_result);
@@ -2053,22 +2053,22 @@ PHP_REDIS_API zval *cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
{
ZVAL_NULL(z_ret);
// Pull our next response if directed
- if(pull) {
- if(cluster_check_response(c, &c->reply_type TSRMLS_CC)<0)
+ if (pull) {
+ if (cluster_check_response(c, &c->reply_type TSRMLS_CC) < 0)
{
return NULL;
}
}
// Validate reply type and length
- if(c->reply_type != TYPE_MULTIBULK || c->reply_len == -1) {
+ if (c->reply_type != TYPE_MULTIBULK || c->reply_len == -1) {
return NULL;
}
array_init(z_ret);
// Call our callback
- if(cb(c->cmd_sock, z_ret, c->reply_len, NULL TSRMLS_CC)==FAILURE) {
+ if (cb(c->cmd_sock, z_ret, c->reply_len, NULL TSRMLS_CC) == FAILURE) {
zval_dtor(z_ret);
return NULL;
}
@@ -2084,7 +2084,7 @@ PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
array_init(multi_resp);
clusterFoldItem *fi = c->multi_head;
- while(fi) {
+ while (fi) {
/* Make sure our transaction didn't fail here */
if (c->multi_len[fi->slot] > -1) {
/* Set the slot where we should look for responses. We don't allow
@@ -2093,7 +2093,7 @@ PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
c->cmd_slot = fi->slot;
c->cmd_sock = SLOT_SOCK(c, fi->slot);
- if(cluster_check_response(c, &c->reply_type TSRMLS_CC)<0) {
+ if (cluster_check_response(c, &c->reply_type TSRMLS_CC) < 0) {
zval_dtor(multi_resp);
RETURN_FALSE;
}
@@ -2121,19 +2121,19 @@ PHP_REDIS_API void cluster_mbulk_mget_resp(INTERNAL_FUNCTION_PARAMETERS,
* to consume the responses. */
c->cmd_sock->serializer = c->flags->serializer;
short fail = c->reply_type != TYPE_MULTIBULK || c->reply_len == -1 ||
- mbulk_resp_loop(c->cmd_sock, mctx->z_multi, c->reply_len, NULL TSRMLS_CC)==FAILURE;
+ mbulk_resp_loop(c->cmd_sock, mctx->z_multi, c->reply_len, NULL TSRMLS_CC) == FAILURE;
// If we had a failure, pad results with FALSE to indicate failure. Non
// existant keys (e.g. for MGET will come back as NULL)
- if(fail) {
- while(mctx->count--) {
+ if (fail) {
+ while (mctx->count--) {
add_next_index_bool(mctx->z_multi, 0);
}
}
// If this is the tail of our multi command, we can set our returns
- if(mctx->last) {
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (mctx->last) {
+ if (CLUSTER_IS_ATOMIC(c)) {
RETVAL_ZVAL(mctx->z_multi, 0, 1);
} else {
add_next_index_zval(&c->multi_resp, mctx->z_multi);
@@ -2152,23 +2152,23 @@ PHP_REDIS_API void cluster_msetnx_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluste
int real_argc = mctx->count/2;
// Protect against an invalid response type
- if(c->reply_type != TYPE_INT) {
+ if (c->reply_type != TYPE_INT) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"Invalid response type for MSETNX");
- while(real_argc--) {
+ while (real_argc--) {
add_next_index_bool(mctx->z_multi, 0);
}
return;
}
// Response will be 1/0 per key, so the client can match them up
- while(real_argc--) {
+ while (real_argc--) {
add_next_index_long(mctx->z_multi, c->reply_len);
}
// Set return value if it's our last response
- if(mctx->last) {
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (mctx->last) {
+ if (CLUSTER_IS_ATOMIC(c)) {
RETVAL_ZVAL(mctx->z_multi, 0, 1);
} else {
add_next_index_zval(&c->multi_resp, mctx->z_multi);
@@ -2186,7 +2186,7 @@ PHP_REDIS_API void cluster_del_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
clusterMultiCtx *mctx = (clusterMultiCtx*)ctx;
// If we get an invalid reply, inform the client
- if(c->reply_type != TYPE_INT) {
+ if (c->reply_type != TYPE_INT) {
php_error_docref(0 TSRMLS_CC, E_WARNING,
"Invalid reply type returned for DEL command");
efree(mctx);
@@ -2196,8 +2196,8 @@ PHP_REDIS_API void cluster_del_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster *
// Increment by the number of keys deleted
Z_LVAL_P(mctx->z_multi) += c->reply_len;
- if(mctx->last) {
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (mctx->last) {
+ if (CLUSTER_IS_ATOMIC(c)) {
ZVAL_LONG(return_value, Z_LVAL_P(mctx->z_multi));
} else {
add_next_index_long(&c->multi_resp, Z_LVAL_P(mctx->z_multi));
@@ -2216,7 +2216,7 @@ PHP_REDIS_API void cluster_mset_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
// If we get an invalid reply type something very wrong has happened,
// and we have to abort.
- if(c->reply_type != TYPE_LINE) {
+ if (c->reply_type != TYPE_LINE) {
php_error_docref(0 TSRMLS_CC, E_ERROR,
"Invalid reply type returned for MSET command");
zval_dtor(mctx->z_multi);
@@ -2226,8 +2226,8 @@ PHP_REDIS_API void cluster_mset_resp(INTERNAL_FUNCTION_PARAMETERS, redisCluster
}
// Set our return if it's the last call
- if(mctx->last) {
- if(CLUSTER_IS_ATOMIC(c)) {
+ if (mctx->last) {
+ if (CLUSTER_IS_ATOMIC(c)) {
ZVAL_BOOL(return_value, zval_is_true(mctx->z_multi));
} else {
add_next_index_bool(&c->multi_resp, zval_is_true(mctx->z_multi));
@@ -2294,10 +2294,10 @@ int mbulk_resp_loop_raw(RedisSock *redis_sock, zval *z_result,
int line_len;
// Iterate over the number we have
- while(count--) {
+ while (count--) {
// Read the line, which should never come back null
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
- if(line == NULL) return FAILURE;
+ if (line == NULL) return FAILURE;
// Add to our result array
add_next_index_stringl(z_result, line, line_len);
@@ -2316,7 +2316,7 @@ int mbulk_resp_loop(RedisSock *redis_sock, zval *z_result,
int line_len;
/* Iterate over the lines we have to process */
- while(count--) {
+ while (count--) {
/* Read our line */
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
@@ -2350,17 +2350,17 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
long long idx = 0;
// Our count wil need to be divisible by 2
- if(count % 2 != 0) {
+ if (count % 2 != 0) {
return -1;
}
// Iterate through our elements
- while(count--) {
+ while (count--) {
// Grab our line, bomb out on failure
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
- if(!line) return -1;
+ if (!line) return -1;
- if(idx++ % 2 == 0) {
+ if (idx++ % 2 == 0) {
// Save our key and length
key = line;
key_len = line_len;
@@ -2393,15 +2393,15 @@ int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
long long idx = 0;
// Our context will need to be divisible by 2
- if(count %2 != 0) {
+ if (count %2 != 0) {
return -1;
}
// While we have elements
- while(count--) {
+ while (count--) {
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
if (line != NULL) {
- if(idx++ % 2 == 0) {
+ if (idx++ % 2 == 0) {
key = line;
key_len = line_len;
} else {
@@ -2430,15 +2430,15 @@ int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC)
{
char *line;
- int line_len,i=0;
+ int line_len,i = 0;
zval *z_keys = ctx;
// Loop while we've got replies
- while(count--) {
+ while (count--) {
zend_string *zstr = zval_get_string(&z_keys[i]);
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
- if(line != NULL) {
+ if (line != NULL) {
zval zv, *z = &zv;
if (redis_unpack(redis_sock, line, line_len, z TSRMLS_CC)) {
#if (PHP_MAJOR_VERSION < 7)