mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Some style normalization
This commit is contained in:
+152
-152
@@ -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;
|
||||
|
||||
+2
-2
@@ -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 */
|
||||
|
||||
+144
-144
@@ -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);
|
||||
|
||||
+187
-187
File diff suppressed because it is too large
Load Diff
+24
-24
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user