diff options
-rw-r--r-- | cluster_library.c | 304 | ||||
-rw-r--r-- | redis.c | 42 | ||||
-rw-r--r-- | redis_array.c | 4 | ||||
-rw-r--r-- | redis_cluster.c | 288 | ||||
-rw-r--r-- | redis_commands.c | 374 | ||||
-rw-r--r-- | redis_session.c | 48 |
6 files changed, 530 insertions, 530 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) @@ -495,7 +495,7 @@ redis_send_discard(RedisSock *redis_sock TSRMLS_DC) (resp = redis_sock_read(redis_sock,&resp_len TSRMLS_CC)) != NULL) { /* success if we get OK */ - result = (resp_len == 3 && strncmp(resp,"+OK", 3)==0) ? SUCCESS:FAILURE; + result = (resp_len == 3 && strncmp(resp,"+OK", 3) == 0) ? SUCCESS:FAILURE; /* free our response */ efree(resp); @@ -1448,7 +1448,7 @@ PHP_METHOD(Redis, sRandMember) // Grab our socket, validate call if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL || redis_srandmember_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, - &cmd, &cmd_len, NULL, NULL, &have_count)==FAILURE) + &cmd, &cmd_len, NULL, NULL, &have_count) == FAILURE) { RETURN_FALSE; } @@ -1457,7 +1457,7 @@ PHP_METHOD(Redis, sRandMember) if(have_count) { if (IS_ATOMIC(redis_sock)) { if(redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, - redis_sock, NULL, NULL)<0) + redis_sock, NULL, NULL) < 0) { RETURN_FALSE; } @@ -1534,7 +1534,7 @@ PHP_METHOD(Redis, sort) { // Grab socket, handle command construction if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL || redis_sort_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, &have_store, - &cmd, &cmd_len, NULL, NULL)==FAILURE) + &cmd, &cmd_len, NULL, NULL) == FAILURE) { RETURN_FALSE; } @@ -1945,14 +1945,14 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, char *cmd; int cmd_len; RedisSock *redis_sock; - int withscores=0; + int withscores = 0; if ((redis_sock = redis_sock_get(getThis() TSRMLS_CC, 0)) == NULL) { RETURN_FALSE; } if(fun(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, kw, &cmd, - &cmd_len, &withscores, NULL, NULL)==FAILURE) + &cmd_len, &withscores, NULL, NULL) == FAILURE) { RETURN_FALSE; } @@ -1966,7 +1966,7 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, } else { if (IS_ATOMIC(redis_sock)) { if(redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, - redis_sock, NULL, NULL)<0) + redis_sock, NULL, NULL) < 0) { RETURN_FALSE; } @@ -1975,14 +1975,14 @@ static void generic_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, char *kw, } } -/* {{{ proto array Redis::zRange(string key,int start,int end,bool scores=0) */ +/* {{{ proto array Redis::zRange(string key,int start,int end,bool scores = 0) */ PHP_METHOD(Redis, zRange) { generic_zrange_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZRANGE", redis_zrange_cmd); } -/* {{{ proto array Redis::zRevRange(string k, long s, long e, bool scores=0) */ +/* {{{ proto array Redis::zRevRange(string k, long s, long e, bool scores = 0) */ PHP_METHOD(Redis, zRevRange) { generic_zrange_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, "ZREVRANGE", redis_zrange_cmd); @@ -2491,7 +2491,7 @@ PHP_METHOD(Redis, subscribe) { * [p]unsubscribe(array(channel_0, channel_1, ..., channel_n)) * response format : * array( - * channel_0 => TRUE|FALSE, + * channel_0 => TRUE|FALSE, * channel_1 => TRUE|FALSE, * ... * channel_n => TRUE|FALSE @@ -2884,7 +2884,7 @@ PHP_METHOD(Redis, pubsub) { int cmd_len; strlen_t kw_len; PUBSUB_TYPE type; - zval *arg=NULL; + zval *arg = NULL; // Parse arguments if(zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), @@ -2904,7 +2904,7 @@ PHP_METHOD(Redis, pubsub) { } else if(!strncasecmp(keyword, "numsub", sizeof("numsub"))) { /* One array argument */ if(ZEND_NUM_ARGS() < 2 || Z_TYPE_P(arg) != IS_ARRAY || - zend_hash_num_elements(Z_ARRVAL_P(arg))==0) + zend_hash_num_elements(Z_ARRVAL_P(arg)) == 0) { RETURN_FALSE; } @@ -2929,7 +2929,7 @@ PHP_METHOD(Redis, pubsub) { if(type == PUBSUB_NUMSUB) { if (IS_ATOMIC(redis_sock)) { if(redis_mbulk_reply_zipped_keys_int(INTERNAL_FUNCTION_PARAM_PASSTHRU, - redis_sock, NULL, NULL)<0) + redis_sock, NULL, NULL) < 0) { RETURN_FALSE; } @@ -2938,7 +2938,7 @@ PHP_METHOD(Redis, pubsub) { } else { if (IS_ATOMIC(redis_sock)) { if(redis_read_variant_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, - redis_sock, NULL, NULL)<0) + redis_sock, NULL, NULL) < 0) { RETURN_FALSE; } @@ -3251,7 +3251,7 @@ PHP_METHOD(Redis, getAuth) { PHP_METHOD(Redis, client) { zval *object; RedisSock *redis_sock; - char *cmd, *opt=NULL, *arg=NULL; + char *cmd, *opt = NULL, *arg = NULL; strlen_t opt_len, arg_len; int cmd_len; @@ -3399,10 +3399,10 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) { zval *object, *z_iter; RedisSock *redis_sock; HashTable *hash; - char *pattern=NULL, *cmd, *key=NULL; - int cmd_len, num_elements, key_free=0; + char *pattern = NULL, *cmd, *key = NULL; + int cmd_len, num_elements, key_free = 0; strlen_t key_len = 0, pattern_len = 0; - zend_long count=0, iter; + zend_long count = 0, iter; /* Different prototype depending on if this is a key based scan */ if(type != TYPE_SCAN) { @@ -3440,11 +3440,11 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) { // The iterator should be passed in as NULL for the first iteration, but we // can treat any NON LONG value as NULL for these purposes as we've // seperated the variable anyway. - if(Z_TYPE_P(z_iter) != IS_LONG || Z_LVAL_P(z_iter)<0) { + if(Z_TYPE_P(z_iter) != IS_LONG || Z_LVAL_P(z_iter) < 0) { /* Convert to long */ convert_to_long(z_iter); iter = 0; - } else if(Z_LVAL_P(z_iter)!=0) { + } else if(Z_LVAL_P(z_iter) != 0) { /* Update our iterator value for the next passthru */ iter = Z_LVAL_P(z_iter); } else { @@ -3480,7 +3480,7 @@ generic_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, REDIS_SCAN_TYPE type) { /* Execute our command getting our new iterator value */ REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len); if(redis_sock_read_scan_reply(INTERNAL_FUNCTION_PARAM_PASSTHRU, - redis_sock,type,&iter)<0) + redis_sock,type,&iter) < 0) { if(key_free) efree(key); RETURN_FALSE; diff --git a/redis_array.c b/redis_array.c index 7fbbc6b4..26d8f343 100644 --- a/redis_array.c +++ b/redis_array.c @@ -135,7 +135,7 @@ redis_array_free(RedisArray *ra) int i; /* Redis objects */ - for(i=0;i<ra->count;i++) { + for(i = 0; i< ra->count; i++) { zval_dtor(&ra->redis[i]); efree(ra->hosts[i]); } @@ -718,7 +718,7 @@ PHP_METHOD(RedisArray, keys) array_init(return_value); /* Iterate our RedisArray nodes */ - for(i=0; i<ra->count; ++i) { + for(i = 0; i < ra->count; ++i) { zval zv, *z_tmp = &zv; #if (PHP_MAJOR_VERSION < 7) /* Return for this node */ 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); diff --git a/redis_commands.c b/redis_commands.c index be331fad..7de08641 100644 --- a/redis_commands.c +++ b/redis_commands.c @@ -151,7 +151,7 @@ int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, strlen_t arg_len; // Parse args - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len) ==FAILURE) { return FAILURE; @@ -173,8 +173,8 @@ int redis_key_long_val_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_long expire; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz", &key, &key_len, - &expire, &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz", &key, &key_len, + &expire, &z_val) == FAILURE) { return FAILURE; } @@ -193,8 +193,8 @@ int redis_key_long_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, val_len; zend_long lval; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &key, &key_len, - &lval, &val, &val_len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &key, &key_len, + &lval, &val, &val_len) == FAILURE) { return FAILURE; } @@ -213,8 +213,8 @@ int redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, - &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &key, &key_len, + &z_val) == FAILURE) { return FAILURE; } @@ -232,8 +232,8 @@ int redis_key_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *key, *val; strlen_t key_len, val_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, - &val, &val_len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &key, &key_len, + &val, &val_len) == FAILURE) { return FAILURE; } @@ -252,8 +252,8 @@ int redis_key_str_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *k, *v1, *v2; strlen_t klen, v1len, v2len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &k, &klen, - &v1, &v1len, &v2, &v2len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &k, &klen, + &v1, &v1len, &v2, &v2len) == FAILURE) { return FAILURE; } @@ -273,8 +273,8 @@ int redis_key_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t k1len, k2len; int k1free, k2free; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &k1, &k1len, - &k2, &k2len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &k1, &k1len, + &k2, &k2len) == FAILURE) { return FAILURE; } @@ -284,16 +284,16 @@ int redis_key_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, k2free = redis_key_prefix(redis_sock, &k2, &k2len); // If a slot is requested, we can test that they hash the same - if(slot) { + if (slot) { // Slots where these keys resolve short slot1 = cluster_hash_key(k1, k1len); short slot2 = cluster_hash_key(k2, k2len); // Check if Redis would give us a CROSSLOT error - if(slot1 != slot2) { + if (slot1 != slot2) { php_error_docref(0 TSRMLS_CC, E_WARNING, "Keys don't hash to the same slot"); - if(k1free) efree(k1); - if(k2free) efree(k2); + if (k1free) efree(k1); + if (k2free) efree(k2); return FAILURE; } @@ -360,8 +360,8 @@ int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; zend_long val1, val2; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &key, &key_len, - &val1, &val2)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &key, &key_len, + &val1, &val2) == FAILURE) { return FAILURE; } @@ -379,7 +379,7 @@ int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *key; strlen_t key_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) ==FAILURE) { return FAILURE; @@ -399,8 +399,8 @@ int redis_key_dbl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; double val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &key, &key_len, - &val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sd", &key, &key_len, + &val) == FAILURE) { return FAILURE; } @@ -424,7 +424,7 @@ int redis_fmt_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len, redis_cmd_init_sstr(&cmdstr, argc, kw[type], strlen(kw[type])); // Append our key if it's not a regular SCAN command - if(type != TYPE_SCAN) { + if (type != TYPE_SCAN) { redis_cmd_append_sstr(&cmdstr, key, key_len); } @@ -432,13 +432,13 @@ int redis_fmt_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len, redis_cmd_append_sstr_long(&cmdstr, it); // Append count if we've got one - if(count) { + if (count) { redis_cmd_append_sstr(&cmdstr,"COUNT",sizeof("COUNT")-1); redis_cmd_append_sstr_long(&cmdstr, count); } // Append pattern if we've got one - if(pat_len) { + if (pat_len) { redis_cmd_append_sstr(&cmdstr,"MATCH",sizeof("MATCH")-1); redis_cmd_append_sstr(&cmdstr,pat,pat_len); } @@ -456,15 +456,15 @@ int redis_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *key; strlen_t key_len; zend_long start, end; - zend_bool ws=0; + zend_bool ws = 0; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll|b", &key, &key_len, - &start, &end, &ws)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll|b", &key, &key_len, + &start, &end, &ws) == FAILURE) { return FAILURE; } - if(ws) { + if (ws) { *cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "kdds", key, key_len, start, end, "WITHSCORES", sizeof("WITHSCORES") - 1); } else { @@ -488,7 +488,7 @@ int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, short *slot, void **ctx) { char *key, *start, *end; - int has_limit=0; + int has_limit = 0; long offset, count; strlen_t key_len, start_len, end_len; zval *z_opt=NULL, *z_ele; @@ -498,7 +498,7 @@ int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, PHPREDIS_NOTUSED(idx); - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|a", &key, &key_len, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss|a", &key, &key_len, &start, &start_len, &end, &end_len, &z_opt) ==FAILURE) { @@ -506,7 +506,7 @@ int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // Check for an options array - if(z_opt && Z_TYPE_P(z_opt)==IS_ARRAY) { + if (z_opt && Z_TYPE_P(z_opt) == IS_ARRAY) { ht_opt = Z_ARRVAL_P(z_opt); ZEND_HASH_FOREACH_KEY_VAL(ht_opt, idx, zkey, z_ele) { /* All options require a string key type */ @@ -568,9 +568,9 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, smart_string cmdstr = {0}; // Parse args - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|a!s", &key, + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa|a!s", &key, &key_len, &z_keys, &z_weights, &agg_op, - &agg_op_len)==FAILURE) + &agg_op_len) == FAILURE) { return FAILURE; } @@ -579,16 +579,16 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, ht_keys = Z_ARRVAL_P(z_keys); // Nothing to do if there aren't any - if((keys_count = zend_hash_num_elements(ht_keys))==0) { + if ((keys_count = zend_hash_num_elements(ht_keys)) == 0) { return FAILURE; } else { argc += keys_count; } // Handle WEIGHTS - if(z_weights != NULL) { + if (z_weights != NULL) { ht_weights = Z_ARRVAL_P(z_weights); - if(zend_hash_num_elements(ht_weights) != keys_count) { + if (zend_hash_num_elements(ht_weights) != keys_count) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "WEIGHTS and keys array should be the same size!"); return FAILURE; @@ -599,8 +599,8 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // AGGREGATE option - if(agg_op_len != 0) { - if(strncasecmp(agg_op, "SUM", sizeof("SUM")) && + if (agg_op_len != 0) { + if (strncasecmp(agg_op, "SUM", sizeof("SUM")) && strncasecmp(agg_op, "MIN", sizeof("MIN")) && strncasecmp(agg_op, "MAX", sizeof("MAX"))) { @@ -623,7 +623,7 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Set our slot, free the key if we prefixed it CMD_SET_SLOT(slot,key,key_len); - if(key_free) efree(key); + if (key_free) efree(key); // Process input keys ZEND_HASH_FOREACH_VAL(ht_keys, z_ele) { @@ -635,12 +635,12 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int key_free = redis_key_prefix(redis_sock, &key, &key_len); // If we're in Cluster mode, verify the slot is the same - if(slot && *slot != cluster_hash_key(key,key_len)) { + if (slot && *slot != cluster_hash_key(key,key_len)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "All keys don't hash to the same slot!"); efree(cmdstr.c); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); return FAILURE; } @@ -649,11 +649,11 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Cleanup zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); } ZEND_HASH_FOREACH_END(); // Weights - if(ht_weights != NULL) { + if (ht_weights != NULL) { redis_cmd_append_sstr(&cmdstr, "WEIGHTS", sizeof("WEIGHTS")-1); // Process our weights @@ -696,7 +696,7 @@ int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // AGGREGATE - if(agg_op_len != 0) { + if (agg_op_len != 0) { redis_cmd_append_sstr(&cmdstr, "AGGREGATE", sizeof("AGGREGATE")-1); redis_cmd_append_sstr(&cmdstr, agg_op, agg_op_len); } @@ -721,8 +721,8 @@ int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int key_free; char *key; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af", &z_arr, - &(sctx->cb), &(sctx->cb_cache))==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af", &z_arr, + &(sctx->cb), &(sctx->cb_cache)) == FAILURE) { efree(sctx); return FAILURE; @@ -732,7 +732,7 @@ int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, sctx->kw = kw; sctx->argc = zend_hash_num_elements(ht_chan); - if(sctx->argc==0) { + if (sctx->argc == 0) { efree(sctx); return FAILURE; } @@ -755,7 +755,7 @@ int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_string_release(zstr); // Free our key if it was prefixed - if(key_free) efree(key); + if (key_free) efree(key); } ZEND_HASH_FOREACH_END(); // Push values out @@ -779,7 +779,7 @@ int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, smart_string cmdstr = {0}; subscribeContext *sctx = emalloc(sizeof(subscribeContext)); - 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) { efree(sctx); return FAILURE; } @@ -787,7 +787,7 @@ int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, ht_arr = Z_ARRVAL_P(z_arr); sctx->argc = zend_hash_num_elements(ht_arr); - if(sctx->argc == 0) { + if (sctx->argc == 0) { efree(sctx); return FAILURE; } @@ -801,7 +801,7 @@ int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, key_free = redis_key_prefix(redis_sock, &key, &key_len); redis_cmd_append_sstr(&cmdstr, key, key_len); - if(key_free) efree(key); + if (key_free) efree(key); } ZEND_HASH_FOREACH_END(); // Push out vals @@ -828,8 +828,8 @@ int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, return FAILURE; } - if(zend_parse_parameters(argc TSRMLS_CC, "sss|ll", &key, &key_len, &min, &min_len, - &max, &max_len, &offset, &count)==FAILURE) + if (zend_parse_parameters(argc TSRMLS_CC, "sss|ll", &key, &key_len, &min, &min_len, + &max, &max_len, &offset, &count) == FAILURE) { return FAILURE; } @@ -867,14 +867,14 @@ int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, min_len, max_len; /* Parse args */ - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &key, &key_len, - &min, &min_len, &max, &max_len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sss", &key, &key_len, + &min, &min_len, &max, &max_len) == FAILURE) { return FAILURE; } /* Quick sanity check on min/max */ - if(min_len<1 || max_len<1 || (min[0]!='(' && min[0]!='[') || + if (min_len<1 || max_len<1 || (min[0]!='(' && min[0]!='[') || (max[0]!='(' && max[0]!='[')) { php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -904,8 +904,8 @@ int redis_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw short prevslot = -1; /* Parse args */ - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|al", &lua, &lua_len, - &z_arr, &num_keys)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|al", &lua, &lua_len, + &z_arr, &num_keys) == FAILURE) { return FAILURE; } @@ -967,7 +967,7 @@ int redis_key_varval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int argc = ZEND_NUM_ARGS(); // We at least need a key and one value - if(argc < 2) { + if (argc < 2) { return FAILURE; } @@ -1063,7 +1063,7 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, short kslot = -1; zend_string *zstr; - if(argc < min_argc) { + if (argc < min_argc) { zend_wrong_param_count(TSRMLS_C); return FAILURE; } @@ -1076,19 +1076,19 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // Handle our "single array" case - if(has_timeout == 0) { - single_array = argc==1 && Z_TYPE(z_args[0])==IS_ARRAY; + if (has_timeout == 0) { + single_array = argc==1 && Z_TYPE(z_args[0]) == IS_ARRAY; } else { - single_array = argc==2 && Z_TYPE(z_args[0])==IS_ARRAY && - Z_TYPE(z_args[1])==IS_LONG; + single_array = argc==2 && Z_TYPE(z_args[0]) == IS_ARRAY && + Z_TYPE(z_args[1]) == IS_LONG; timeout = Z_LVAL(z_args[1]); } // If we're running a single array, rework args - if(single_array) { + if (single_array) { ht_arr = Z_ARRVAL(z_args[0]); argc = zend_hash_num_elements(ht_arr); - if(has_timeout) argc++; + if (has_timeout) argc++; efree(z_args); z_args = NULL; @@ -1099,7 +1099,7 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Begin construction of our command redis_cmd_init_sstr(&cmdstr, argc, kw, kw_len); - if(single_array) { + if (single_array) { ZEND_HASH_FOREACH_VAL(ht_arr, z_ele) { zstr = zval_get_string(z_ele); key = ZSTR_VAL(zstr); @@ -1107,12 +1107,12 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, key_free = redis_key_prefix(redis_sock, &key, &key_len); // Protect against CROSSLOT errors - if(slot) { - if(kslot == -1) { + if (slot) { + if (kslot == -1) { kslot = cluster_hash_key(key, key_len); - } else if(cluster_hash_key(key,key_len)!=kslot) { + } else if (cluster_hash_key(key,key_len)!=kslot) { zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not all keys hash to the same slot!"); return FAILURE; @@ -1122,13 +1122,13 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Append this key, free it if we prefixed redis_cmd_append_sstr(&cmdstr, key, key_len); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); } ZEND_HASH_FOREACH_END(); - if(has_timeout) { + if (has_timeout) { redis_cmd_append_sstr_long(&cmdstr, timeout); } } else { - if(has_timeout && Z_TYPE(z_args[argc-1])!=IS_LONG) { + if (has_timeout && Z_TYPE(z_args[argc-1])!=IS_LONG) { php_error_docref(NULL TSRMLS_CC, E_ERROR, "Timeout value must be a LONG"); efree(z_args); @@ -1136,7 +1136,7 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } tail = has_timeout ? argc-1 : argc; - for(i=0;i<tail;i++) { + for(i = 0; i < tail; i++) { zstr = zval_get_string(&z_args[i]); key = ZSTR_VAL(zstr); key_len = ZSTR_LEN(zstr); @@ -1145,13 +1145,13 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, /* Protect against CROSSSLOT errors if we've got a slot */ if (slot) { - if( kslot == -1) { + if ( kslot == -1) { kslot = cluster_hash_key(key, key_len); - } else if(cluster_hash_key(key,key_len)!=kslot) { + } else if (cluster_hash_key(key,key_len)!=kslot) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Not all keys hash to the same slot"); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); efree(z_args); return FAILURE; } @@ -1160,9 +1160,9 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Append this key redis_cmd_append_sstr(&cmdstr, key, key_len); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); } - if(has_timeout) { + if (has_timeout) { redis_cmd_append_sstr_long(&cmdstr, Z_LVAL(z_args[tail])); } @@ -1171,7 +1171,7 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // Push out parameters - if(slot) *slot = kslot; + if (slot) *slot = kslot; *cmd = cmdstr.c; *cmd_len = cmdstr.len; @@ -1193,22 +1193,22 @@ int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; // Make sure the function is being called correctly - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &key, &key_len, - &z_value, &z_opts)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &key, &key_len, + &z_value, &z_opts) == FAILURE) { return FAILURE; } /* Our optional argument can either be a long (to support legacy SETEX */ /* redirection), or an array with Redis >= 2.6.12 set options */ - if(z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY + if (z_opts && Z_TYPE_P(z_opts) != IS_LONG && Z_TYPE_P(z_opts) != IS_ARRAY && Z_TYPE_P(z_opts) != IS_NULL) { return FAILURE; } // Check for an options array - if(z_opts && Z_TYPE_P(z_opts) == IS_ARRAY) { + if (z_opts && Z_TYPE_P(z_opts) == IS_ARRAY) { HashTable *kt = Z_ARRVAL_P(z_opts); zend_string *zkey; ulong idx; @@ -1239,7 +1239,7 @@ int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, set_type = Z_STRVAL_P(v); } } ZEND_HASH_FOREACH_END(); - } else if(z_opts && Z_TYPE_P(z_opts) == IS_LONG) { + } else if (z_opts && Z_TYPE_P(z_opts) == IS_LONG) { /* Grab expiry and fail if it's < 1 */ expire = Z_LVAL_P(z_opts); if (expire < 1) { @@ -1248,19 +1248,19 @@ int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } /* Now let's construct the command we want */ - if(exp_type && set_type) { + if (exp_type && set_type) { /* SET <key> <value> NX|XX PX|EX <timeout> */ *cmd_len = REDIS_CMD_SPPRINTF(cmd, "SET", "kvsls", key, key_len, z_value, exp_type, 2, expire, set_type, 2); - } else if(exp_type) { + } else if (exp_type) { /* SET <key> <value> PX|EX <timeout> */ *cmd_len = REDIS_CMD_SPPRINTF(cmd, "SET", "kvsl", key, key_len, z_value, exp_type, 2, expire); - } else if(set_type) { + } else if (set_type) { /* SET <key> <value> NX|XX */ *cmd_len = REDIS_CMD_SPPRINTF(cmd, "SET", "kvs", key, key_len, z_value, set_type, 2); - } else if(expire > 0) { + } else if (expire > 0) { /* Backward compatible SETEX redirection */ *cmd_len = REDIS_CMD_SPPRINTF(cmd, "SETEX", "klv", key, key_len, expire, z_value); @@ -1282,8 +1282,8 @@ int redis_brpoplpush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, short slot1, slot2; zend_long timeout; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &key1, &key1_len, - &key2, &key2_len, &timeout)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &key1, &key1_len, + &key2, &key2_len, &timeout) == FAILURE) { return FAILURE; } @@ -1296,11 +1296,11 @@ int redis_brpoplpush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, if (slot) { slot1 = cluster_hash_key(key1, key1_len); slot2 = cluster_hash_key(key2, key2_len); - if(slot1 != slot2) { + if (slot1 != slot2) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Keys hash to different slots!"); - if(key1_free) efree(key1); - if(key2_free) efree(key2); + if (key1_free) efree(key1); + if (key2_free) efree(key2); return FAILURE; } @@ -1309,7 +1309,7 @@ int redis_brpoplpush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // Consistency with Redis, if timeout < 0 use RPOPLPUSH - if(timeout < 0) { + if (timeout < 0) { *cmd_len = REDIS_CMD_SPPRINTF(cmd, "RPOPLPUSH", "ss", key1, key1_len, key2, key2_len); } else { @@ -1339,7 +1339,7 @@ redis_atomic_increment(INTERNAL_FUNCTION_PARAMETERS, int type, zend_long val = 1; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &key_len, - &val)==FAILURE) + &val) == FAILURE) { return FAILURE; } @@ -1388,8 +1388,8 @@ int redis_hincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, mem_len; zend_long byval; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &key, &key_len, - &mem, &mem_len, &byval)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl", &key, &key_len, + &mem, &mem_len, &byval) == FAILURE) { return FAILURE; } @@ -1409,8 +1409,8 @@ int redis_hincrbyfloat_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, mem_len; double byval; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssd", &key, &key_len, - &mem, &mem_len, &byval)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssd", &key, &key_len, + &mem, &mem_len, &byval) == FAILURE) { return FAILURE; } @@ -1429,14 +1429,14 @@ int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, { char *key; zval *z_arr, *z_mems, *z_mem; - int i, count, valid=0, key_free; + int i, count, valid = 0, key_free; strlen_t key_len; HashTable *ht_arr; smart_string cmdstr = {0}; // Parse arguments - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, - &z_arr)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, + &z_arr) == FAILURE) { return FAILURE; } @@ -1445,7 +1445,7 @@ int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, ht_arr = Z_ARRVAL_P(z_arr); // We can abort if we have no elements - if((count = zend_hash_num_elements(ht_arr))==0) { + if ((count = zend_hash_num_elements(ht_arr)) == 0) { return FAILURE; } @@ -1468,7 +1468,7 @@ int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } ZEND_HASH_FOREACH_END(); // If nothing was valid, fail - if(valid == 0) { + if (valid == 0) { efree(z_mems); return FAILURE; } @@ -1486,7 +1486,7 @@ int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, redis_cmd_append_sstr(&cmdstr, key, key_len); // Iterate over members, appending as arguments - for(i=0;i<valid;i++) { + for(i = 0; i< valid; i++) { zend_string *zstr = zval_get_string(&z_mems[i]); redis_cmd_append_sstr(&cmdstr, ZSTR_VAL(zstr), ZSTR_LEN(zstr)); zend_string_release(zstr); @@ -1496,7 +1496,7 @@ int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, CMD_SET_SLOT(slot,key,key_len); // Free our key if we prefixed it - if(key_free) efree(key); + if (key_free) efree(key); // Push out command, length, and key context *cmd = cmdstr.c; @@ -1522,14 +1522,14 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_val; // Parse args - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, - &z_arr)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, + &z_arr) == FAILURE) { return FAILURE; } // We can abort if we have no fields - if((count = zend_hash_num_elements(Z_ARRVAL_P(z_arr)))==0) { + if ((count = zend_hash_num_elements(Z_ARRVAL_P(z_arr))) == 0) { return FAILURE; } @@ -1574,7 +1574,7 @@ int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, CMD_SET_SLOT(slot,key,key_len); // Free our key if we prefixed it - if(key_free) efree(key); + if (key_free) efree(key); // Push return pointers *cmd_len = cmdstr.len; @@ -1613,21 +1613,21 @@ int redis_bitpos_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; argc = ZEND_NUM_ARGS(); - if(zend_parse_parameters(argc TSRMLS_CC, "sl|ll", &key, &key_len, &bit, - &start, &end)==FAILURE) + if (zend_parse_parameters(argc TSRMLS_CC, "sl|ll", &key, &key_len, &bit, + &start, &end) == FAILURE) { return FAILURE; } // Prevalidate bit - if(bit != 0 && bit != 1) { + if (bit != 0 && bit != 1) { return FAILURE; } // Construct command based on arg count - if(argc == 2) { + if (argc == 2) { *cmd_len = REDIS_CMD_SPPRINTF(cmd, "BITPOS", "kd", key, key_len, bit); - } else if(argc == 3) { + } else if (argc == 3) { *cmd_len = REDIS_CMD_SPPRINTF(cmd, "BITPOS", "kdd", key, key_len, bit, start); } else { @@ -1660,14 +1660,14 @@ int redis_bitop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } // If we were passed a slot pointer, init to a sentinel value - if(slot) *slot = -1; + if (slot) *slot = -1; // Initialize command construction, add our operation argument redis_cmd_init_sstr(&cmdstr, argc, "BITOP", sizeof("BITOP")-1); redis_cmd_append_sstr(&cmdstr, Z_STRVAL(z_args[0]), Z_STRLEN(z_args[0])); // Now iterate over our keys argument - for(i=1;i<argc;i++) { + for (i = 1; i < argc; i++) { // Make sure we've got a string zstr = zval_get_string(&z_args[i]); @@ -1680,13 +1680,13 @@ int redis_bitop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, redis_cmd_append_sstr(&cmdstr, key, key_len); // Verify slot if this is a Cluster request - if(slot) { + if (slot) { kslot = cluster_hash_key(key, key_len); - if(*slot == -1 || kslot != *slot) { + if (*slot == -1 || kslot != *slot) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Warning, not all keys hash to the same slot!"); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); efree(z_args); return FAILURE; } @@ -1694,7 +1694,7 @@ int redis_bitop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); } // Free our argument array @@ -1715,8 +1715,8 @@ int redis_bitcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; zend_long start = 0, end = -1; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &key, &key_len, - &start, &end)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &key, &key_len, + &start, &end) == FAILURE) { return FAILURE; } @@ -1742,8 +1742,8 @@ static int redis_gen_pf_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_string *zstr; // Parse arguments - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, - &z_arr)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sa", &key, &key_len, + &z_arr) == FAILURE) { return FAILURE; } @@ -1753,25 +1753,25 @@ static int redis_gen_pf_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, argc += zend_hash_num_elements(ht_arr); // We need at least two arguments - if(argc < 2) { + if (argc < 2) { return FAILURE; } // Prefix key, set initial hash slot key_free = redis_key_prefix(redis_sock, &key, &key_len); - if(slot) *slot = cluster_hash_key(key, key_len); + if (slot) *slot = cluster_hash_key(key, key_len); // Start command construction redis_cmd_init_sstr(&cmdstr, argc, kw, kw_len); redis_cmd_append_sstr(&cmdstr, key, key_len); // Free key if we prefixed - if(key_free) efree(key); + if (key_free) efree(key); // Now iterate over the rest of our keys or values ZEND_HASH_FOREACH_VAL(ht_arr, z_ele) { // Prefix keys, serialize values - if(is_keys) { + if (is_keys) { zstr = zval_get_string(z_ele); mem = ZSTR_VAL(zstr); mem_len = ZSTR_LEN(zstr); @@ -1780,18 +1780,18 @@ static int redis_gen_pf_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, mem_free = redis_key_prefix(redis_sock, &mem, &mem_len); // Verify slot - if(slot && *slot != cluster_hash_key(mem, mem_len)) { + if (slot && *slot != cluster_hash_key(mem, mem_len)) { php_error_docref(0 TSRMLS_CC, E_WARNING, "All keys must hash to the same slot!"); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); return FAILURE; } } else { mem_free = redis_pack(redis_sock, z_ele, &mem, &mem_len TSRMLS_CC); zstr = NULL; - if(!mem_free) { + if (!mem_free) { zstr = zval_get_string(z_ele); mem = ZSTR_VAL(zstr); mem_len = ZSTR_LEN(zstr); @@ -1803,7 +1803,7 @@ static int redis_gen_pf_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Clean up any allocated memory if (zstr) zend_string_release(zstr); - if(mem_free) efree(mem); + if (mem_free) efree(mem); } ZEND_HASH_FOREACH_END(); // Push output arguments @@ -1842,7 +1842,7 @@ int redis_pfcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, short kslot=-1; zend_string *zstr; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"z",&z_keys)==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,"z",&z_keys) == FAILURE) { return FAILURE; } @@ -1877,7 +1877,7 @@ int redis_pfcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, if (slot) { if (kslot == -1) { kslot = cluster_hash_key(key, key_len); - } else if(cluster_hash_key(key,key_len)!=kslot) { + } else if (cluster_hash_key(key,key_len)!=kslot) { zend_string_release(zstr); if (key_free) efree(key); efree(cmdstr.c); @@ -1924,7 +1924,7 @@ int redis_auth_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *pw; strlen_t pw_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pw, &pw_len) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &pw, &pw_len) ==FAILURE) { return FAILURE; @@ -1950,14 +1950,14 @@ int redis_setbit_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_long offset; zend_bool val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slb", &key, &key_len, - &offset, &val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slb", &key, &key_len, + &offset, &val) == FAILURE) { return FAILURE; } // Validate our offset - if(offset < BITOP_MIN_OFFSET || offset > BITOP_MAX_OFFSET) { + if (offset < BITOP_MIN_OFFSET || offset > BITOP_MAX_OFFSET) { php_error_docref(0 TSRMLS_CC, E_WARNING, "Invalid OFFSET for bitop command (must be between 0-2^32-1)"); return FAILURE; @@ -1976,14 +1976,14 @@ int redis_linsert_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, pos_len; zval *z_val, *z_pivot; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sszz", &key, &key_len, - &pos, &pos_len, &z_pivot, &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sszz", &key, &key_len, + &pos, &pos_len, &z_pivot, &z_val) == FAILURE) { return FAILURE; } // Validate position - if(strncasecmp(pos, "after", 5) && strncasecmp(pos, "before", 6)) { + if (strncasecmp(pos, "after", 5) && strncasecmp(pos, "before", 6)) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Position must be either 'BEFORE' or 'AFTER'"); return FAILURE; @@ -2006,8 +2006,8 @@ int redis_lrem_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_long count = 0; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &key, &key_len, - &z_val, &count)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &key, &key_len, + &z_val, &count) == FAILURE) { return FAILURE; } @@ -2027,8 +2027,8 @@ int redis_smove_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int src_free, dst_free; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &src, &src_len, - &dst, &dst_len, &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &src, &src_len, + &dst, &dst_len, &z_val) == FAILURE) { return FAILURE; } @@ -2040,11 +2040,11 @@ int redis_smove_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, if (slot) { short slot1 = cluster_hash_key(src, src_len); short slot2 = cluster_hash_key(dst, dst_len); - if(slot1 != slot2) { + if (slot1 != slot2) { php_error_docref(0 TSRMLS_CC, E_WARNING, "Source and destination keys don't hash to the same slot!"); - if(src_free) efree(src); - if(dst_free) efree(dst); + if (src_free) efree(src); + if (dst_free) efree(dst); return FAILURE; } *slot = slot1; @@ -2055,8 +2055,8 @@ int redis_smove_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, dst_len, z_val); // Cleanup - if(src_free) efree(src); - if(dst_free) efree(dst); + if (src_free) efree(src); + if (dst_free) efree(dst); // Succcess! return SUCCESS; @@ -2070,8 +2070,8 @@ static int gen_hset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len, mem_len; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &key, &key_len, - &mem, &mem_len, &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssz", &key, &key_len, + &mem, &mem_len, &z_val) == FAILURE) { return FAILURE; } @@ -2108,8 +2108,8 @@ int redis_srandmember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; zend_long count; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &key_len, - &count)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &key, &key_len, + &count) == FAILURE) { return FAILURE; } @@ -2136,8 +2136,8 @@ int redis_zincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, double incrby; zval *z_val; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdz", &key, &key_len, - &incrby, &z_val)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sdz", &key, &key_len, + &incrby, &z_val) == FAILURE) { return FAILURE; } @@ -2159,8 +2159,8 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t key_len; int key_free; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &key, &key_len, - &z_opts)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a", &key, &key_len, + &z_opts) == FAILURE) { return FAILURE; } @@ -2199,7 +2199,7 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, ) && Z_TYPE_P(z_ele) == IS_STRING ) { // "BY" option is disabled in cluster - if(slot) { + if (slot) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "SORT BY option is not allowed in Redis Cluster"); zval_dtor(&z_argv); @@ -2229,7 +2229,7 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int cross_slot = slot && *slot != cluster_hash_key( Z_STRVAL_P(z_ele), Z_STRLEN_P(z_ele)); - if(cross_slot) { + if (cross_slot) { php_error_docref(0 TSRMLS_CC, E_WARNING, "Error, SORT key and STORE key have different slots!"); zval_dtor(&z_argv); @@ -2250,7 +2250,7 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, ) && (Z_TYPE_P(z_ele) == IS_STRING || Z_TYPE_P(z_ele) == IS_ARRAY) ) { // Disabled in cluster - if(slot) { + if (slot) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "GET option for SORT disabled in Redis Cluster"); zval_dtor(&z_argv); @@ -2262,7 +2262,7 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, add_next_index_stringl(&z_argv, "GET", sizeof("GET") - 1); add_next_index_stringl(&z_argv, Z_STRVAL_P(z_ele), Z_STRLEN_P(z_ele)); } else { - int added=0; + int added = 0; zval *z_key; ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(z_ele), z_key) { @@ -2279,7 +2279,7 @@ int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, } ZEND_HASH_FOREACH_END(); // Make sure we were able to add at least one - if(added==0) { + if (added == 0) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Array of GET values requested, but none are valid"); zval_dtor(&z_argv); @@ -2378,7 +2378,7 @@ int redis_hdel_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zend_string *zstr; // We need at least KEY and one member - if(argc < 2) { + if (argc < 2) { return FAILURE; } @@ -2404,10 +2404,10 @@ int redis_hdel_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Set our slot, free key if we prefixed it CMD_SET_SLOT(slot,arg,arg_len); zend_string_release(zstr); - if(arg_free) efree(arg); + if (arg_free) efree(arg); // Iterate through the members we're removing - for(i=1;i<argc;i++) { + for (i = 1; i < argc; i++) { zstr = zval_get_string(&z_args[i]); redis_cmd_append_sstr(&cmdstr, ZSTR_VAL(zstr), ZSTR_LEN(zstr)); zend_string_release(zstr); @@ -2493,7 +2493,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, // Set our slot, free key if we prefixed it CMD_SET_SLOT(slot,key,key_len); zend_string_release(zstr); - if(key_free) efree(key); + if (key_free) efree(key); if (exp_type) redis_cmd_append_sstr(&cmdstr, exp_type, 2); if (ch) redis_cmd_append_sstr(&cmdstr, "CH", 2); @@ -2518,7 +2518,7 @@ int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, redis_cmd_append_sstr(&cmdstr, val, val_len); // Free value if we serialized - if(val_free) efree(val); + if (val_free) efree(val); i += 2; } @@ -2540,8 +2540,8 @@ int redis_object_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *key, *subcmd; strlen_t key_len, subcmd_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &subcmd, - &subcmd_len, &key, &key_len)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &subcmd, + &subcmd_len, &key, &key_len) == FAILURE) { return FAILURE; } @@ -2550,11 +2550,11 @@ int redis_object_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, *cmd_len = REDIS_CMD_SPPRINTF(cmd, "OBJECT", "sk", subcmd, subcmd_len, key, key_len); // Push the reply type to our caller - if(subcmd_len == 8 && (!strncasecmp(subcmd,"refcount",8) || + if (subcmd_len == 8 && (!strncasecmp(subcmd,"refcount",8) || !strncasecmp(subcmd,"idletime",8))) { *rtype = TYPE_INT; - } else if(subcmd_len == 8 && !strncasecmp(subcmd, "encoding", 8)) { + } else if (subcmd_len == 8 && !strncasecmp(subcmd, "encoding", 8)) { *rtype = TYPE_BULK; } else { php_error_docref(NULL TSRMLS_CC, E_WARNING, @@ -2984,14 +2984,14 @@ int redis_command_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, strlen_t kw_len; /* Parse our args */ - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz", &kw, &kw_len, - &z_arg)==FAILURE) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sz", &kw, &kw_len, + &z_arg) == FAILURE) { return FAILURE; } /* Construct our command */ - if(!kw) { + if (!kw) { *cmd_len = REDIS_CMD_SPPRINTF(cmd, "COMMAND", ""); } else if (!z_arg) { /* Sanity check */ @@ -3013,7 +3013,7 @@ int redis_command_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, int arr_len; /* Sanity check on args */ - if(strncasecmp(kw, "getkeys", sizeof("getkeys")-1) || + if (strncasecmp(kw, "getkeys", sizeof("getkeys")-1) || Z_TYPE_P(z_arg)!=IS_ARRAY || (arr_len=zend_hash_num_elements(Z_ARRVAL_P(z_arg)))<1) { @@ -3135,7 +3135,7 @@ void redis_setoption_handler(INTERNAL_FUNCTION_PARAMETERS, RETURN_TRUE; case REDIS_OPT_READ_TIMEOUT: redis_sock->read_timeout = atof(val_str); - if(redis_sock->stream) { + if (redis_sock->stream) { read_tv.tv_sec = (time_t)redis_sock->read_timeout; read_tv.tv_usec = (int)((redis_sock->read_timeout - read_tv.tv_sec) * 1000000); @@ -3154,7 +3154,7 @@ void redis_setoption_handler(INTERNAL_FUNCTION_PARAMETERS, if (redis_sock->tcp_keepalive == tcp_keepalive) { RETURN_TRUE; } - if(redis_sock->stream) { + if (redis_sock->stream) { /* set TCP_KEEPALIVE */ sock = (php_netstream_data_t*)redis_sock->stream->abstract; if (setsockopt(sock->socket, SOL_SOCKET, SO_KEEPALIVE, (char*)&tcp_keepalive, @@ -3166,7 +3166,7 @@ void redis_setoption_handler(INTERNAL_FUNCTION_PARAMETERS, RETURN_TRUE; case REDIS_OPT_SCAN: val_long = atol(val_str); - if(val_long==REDIS_SCAN_NORETRY || val_long==REDIS_SCAN_RETRY) { + if (val_long==REDIS_SCAN_NORETRY || val_long==REDIS_SCAN_RETRY) { redis_sock->scan = val_long; RETURN_TRUE; } @@ -3191,7 +3191,7 @@ void redis_prefix_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock) { char *key; strlen_t key_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &key, &key_len) ==FAILURE) { RETURN_FALSE; @@ -3213,14 +3213,14 @@ void redis_serialize_handler(INTERNAL_FUNCTION_PARAMETERS, char *val; strlen_t val_len; - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_val)==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &z_val) == FAILURE) { RETURN_FALSE; } int val_free = redis_serialize(redis_sock, z_val, &val, &val_len TSRMLS_CC); RETVAL_STRINGL(val, val_len); - if(val_free) efree(val); + if (val_free) efree(val); } void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS, @@ -3230,7 +3230,7 @@ void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS, strlen_t value_len; // Parse our arguments - if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &value, &value_len) == FAILURE) { RETURN_FALSE; diff --git a/redis_session.c b/redis_session.c index 86004b7f..2a36c625 100644 --- a/redis_session.c +++ b/redis_session.c @@ -97,12 +97,12 @@ redis_pool_free(redis_pool *pool TSRMLS_DC) { redis_pool_member *rpm, *next; rpm = pool->head; - while(rpm) { + while (rpm) { next = rpm->next; redis_sock_disconnect(rpm->redis_sock TSRMLS_CC); redis_free_socket(rpm->redis_sock); - if(rpm->prefix) zend_string_release(rpm->prefix); - if(rpm->auth) zend_string_release(rpm->auth); + if (rpm->prefix) zend_string_release(rpm->prefix); + if (rpm->auth) zend_string_release(rpm->auth); efree(rpm); rpm = next; } @@ -121,7 +121,7 @@ redis_pool_member_auth(redis_pool_member *rpm TSRMLS_DC) { } cmd_len = REDIS_SPPRINTF(&cmd, "AUTH", "S", rpm->auth); - if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) >= 0) { + if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) >= 0) { if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))) { efree(response); } @@ -136,7 +136,7 @@ redis_pool_member_select(redis_pool_member *rpm TSRMLS_DC) { int response_len, cmd_len; cmd_len = REDIS_SPPRINTF(&cmd, "SELECT", "d", rpm->database); - if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) >= 0) { + if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) >= 0) { if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC))) { efree(response); } @@ -154,16 +154,16 @@ redis_pool_get_sock(redis_pool *pool, const char *key TSRMLS_DC) { redis_pool_member *rpm = pool->head; for(i = 0; i < pool->totalWeight;) { - if(pos >= i && pos < i + rpm->weight) { + if (pos >= i && pos < i + rpm->weight) { int needs_auth = 0; if (rpm->auth && rpm->redis_sock->status != REDIS_SOCK_STATUS_CONNECTED) { needs_auth = 1; } redis_sock_server_open(rpm->redis_sock TSRMLS_CC); - if(needs_auth) { + if (needs_auth) { redis_pool_member_auth(rpm TSRMLS_CC); } - if(rpm->database >= 0) { /* default is -1 which leaves the choice to redis. */ + if (rpm->database >= 0) { /* default is -1 which leaves the choice to redis. */ redis_pool_member_select(rpm TSRMLS_CC); } @@ -186,9 +186,9 @@ PS_OPEN_FUNC(redis) redis_pool *pool = redis_pool_new(TSRMLS_C); - for (i=0,j=0,path_len=strlen(save_path); i<path_len; i=j+1) { + for (i = 0, j = 0, path_len = strlen(save_path); i < path_len; i = j + 1) { /* find beginning of url */ - while (i<path_len && (isspace(save_path[i]) || save_path[i] == ',')) + while ( i< path_len && (isspace(save_path[i]) || save_path[i] == ',')) i++; /* find end of url */ @@ -279,7 +279,7 @@ PS_OPEN_FUNC(redis) } RedisSock *redis_sock; - if(url->host) { + if (url->host) { #if (PHP_VERSION_ID < 70300) redis_sock = redis_sock_create(url->host, strlen(url->host), url->port, timeout, read_timeout, persistent, persistent_id, retry_interval, 0); #else @@ -313,7 +313,7 @@ PS_CLOSE_FUNC(redis) { redis_pool *pool = PS_GET_MOD_DATA(); - if(pool){ + if (pool){ redis_pool_free(pool TSRMLS_CC); PS_SET_MOD_DATA(NULL); } @@ -329,7 +329,7 @@ redis_session_key(redis_pool_member *rpm, const char *key, int key_len, int *ses char *prefix = default_prefix; size_t prefix_len = sizeof(default_prefix)-1; - if(rpm->prefix) { + if (rpm->prefix) { prefix = ZSTR_VAL(rpm->prefix); prefix_len = ZSTR_LEN(rpm->prefix); } @@ -362,7 +362,7 @@ PS_READ_FUNC(redis) redis_pool *pool = PS_GET_MOD_DATA(); redis_pool_member *rpm = redis_pool_get_sock(pool, skey TSRMLS_CC); RedisSock *redis_sock = rpm?rpm->redis_sock:NULL; - if(!rpm || !redis_sock){ + if (!rpm || !redis_sock){ return FAILURE; } @@ -371,7 +371,7 @@ PS_READ_FUNC(redis) cmd_len = REDIS_SPPRINTF(&cmd, "GET", "s", resp, resp_len); efree(resp); - if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { + if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { efree(cmd); return FAILURE; } @@ -423,7 +423,7 @@ PS_WRITE_FUNC(redis) redis_pool *pool = PS_GET_MOD_DATA(); redis_pool_member *rpm = redis_pool_get_sock(pool, skey TSRMLS_CC); RedisSock *redis_sock = rpm?rpm->redis_sock:NULL; - if(!rpm || !redis_sock){ + if (!rpm || !redis_sock){ return FAILURE; } @@ -432,7 +432,7 @@ PS_WRITE_FUNC(redis) cmd_len = REDIS_SPPRINTF(&cmd, "SETEX", "sds", session, session_len, INI_INT("session.gc_maxlifetime"), sval, svallen); efree(session); - if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { + if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { efree(cmd); return FAILURE; } @@ -443,7 +443,7 @@ PS_WRITE_FUNC(redis) return FAILURE; } - if(response_len == 3 && strncmp(response, "+OK", 3) == 0) { + if (response_len == 3 && strncmp(response, "+OK", 3) == 0) { efree(response); return SUCCESS; } else { @@ -470,7 +470,7 @@ PS_DESTROY_FUNC(redis) redis_pool *pool = PS_GET_MOD_DATA(); redis_pool_member *rpm = redis_pool_get_sock(pool, skey TSRMLS_CC); RedisSock *redis_sock = rpm?rpm->redis_sock:NULL; - if(!rpm || !redis_sock){ + if (!rpm || !redis_sock){ return FAILURE; } @@ -478,7 +478,7 @@ PS_DESTROY_FUNC(redis) session = redis_session_key(rpm, skey, skeylen, &session_len); cmd_len = REDIS_SPPRINTF(&cmd, "DEL", "s", session, session_len); efree(session); - if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { + if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { efree(cmd); return FAILURE; } @@ -489,7 +489,7 @@ PS_DESTROY_FUNC(redis) return FAILURE; } - if(response_len == 2 && response[0] == ':' && (response[1] == '0' || response[1] == '1')) { + if (response_len == 2 && response[0] == ':' && (response[1] == '0' || response[1] == '1')) { efree(response); return SUCCESS; } else { @@ -663,7 +663,7 @@ PS_READ_FUNC(rediscluster) { /* Attempt to kick off our command */ c->readonly = 1; - if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC)<0 || c->err) { + if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC) < 0 || c->err) { efree(cmd); return FAILURE; } @@ -727,7 +727,7 @@ PS_WRITE_FUNC(rediscluster) { /* Attempt to send command */ c->readonly = 0; - if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC)<0 || c->err) { + if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC) < 0 || c->err) { efree(cmd); return FAILURE; } @@ -767,7 +767,7 @@ PS_DESTROY_FUNC(rediscluster) { efree(skey); /* Attempt to send command */ - if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC)<0 || c->err) { + if (cluster_send_command(c,slot,cmd,cmdlen TSRMLS_CC) < 0 || c->err) { efree(cmd); return FAILURE; } |