Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d6c52e

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Small cosmetic changes in cluster_library
1 parent dc1f239 commit 1d6c52e

2 files changed

Lines changed: 20 additions & 41 deletions

File tree

cluster_library.c

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,7 @@ static int cluster_send_direct(RedisSock *redis_sock, char *cmd, int cmd_len,
273273
}
274274

275275
static int cluster_send_asking(RedisSock *redis_sock) {
276-
return cluster_send_direct(redis_sock, RESP_ASKING_CMD,
277-
sizeof(RESP_ASKING_CMD)-1, TYPE_LINE);
276+
return cluster_send_direct(redis_sock, ZEND_STRL(RESP_ASKING_CMD), TYPE_LINE);
278277
}
279278

280279
/* Send READONLY to a specific RedisSock unless it's already flagged as being
@@ -287,8 +286,7 @@ static int cluster_send_readonly(RedisSock *redis_sock) {
287286
if (redis_sock->readonly) return 0;
288287

289288
/* Return success if we can send it */
290-
ret = cluster_send_direct(redis_sock, RESP_READONLY_CMD,
291-
sizeof(RESP_READONLY_CMD) - 1, TYPE_LINE);
289+
ret = cluster_send_direct(redis_sock, ZEND_STRL(RESP_READONLY_CMD), TYPE_LINE);
292290

293291
/* Flag this socket as READONLY if our command worked */
294292
redis_sock->readonly = !ret;
@@ -315,8 +313,7 @@ PHP_REDIS_API int cluster_send_exec(redisCluster *c, short slot) {
315313
int retval;
316314

317315
/* Send exec */
318-
retval = cluster_send_slot(c, slot, RESP_EXEC_CMD, sizeof(RESP_EXEC_CMD)-1,
319-
TYPE_MULTIBULK);
316+
retval = cluster_send_slot(c, slot, ZEND_STRL(RESP_EXEC_CMD), TYPE_MULTIBULK);
320317

321318
/* We'll either get a length corresponding to the number of commands sent to
322319
* this node, or -1 in the case of EXECABORT or WATCH failure. */
@@ -327,8 +324,7 @@ PHP_REDIS_API int cluster_send_exec(redisCluster *c, short slot) {
327324
}
328325

329326
PHP_REDIS_API int cluster_send_discard(redisCluster *c, short slot) {
330-
if (cluster_send_direct(SLOT_SOCK(c,slot), RESP_DISCARD_CMD,
331-
sizeof(RESP_DISCARD_CMD)-1, TYPE_LINE))
327+
if (cluster_send_direct(SLOT_SOCK(c,slot), ZEND_STRL(RESP_DISCARD_CMD), TYPE_LINE))
332328
{
333329
return 0;
334330
}
@@ -1124,6 +1120,10 @@ static int cluster_set_redirection(redisCluster* c, char *msg, int moved)
11241120
{
11251121
char *host, *port;
11261122

1123+
/* The Redis Cluster specification suggests clients do not update
1124+
* their slot mapping for an ASK redirection, only for MOVED */
1125+
if (moved) c->redirections++;
1126+
11271127
/* Move past "MOVED" or "ASK */
11281128
msg += moved ? MOVED_LEN : ASK_LEN;
11291129

@@ -1182,22 +1182,12 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type)
11821182

11831183
// Check for MOVED or ASK redirection
11841184
if ((moved = IS_MOVED(inbuf)) || IS_ASK(inbuf)) {
1185-
/* The Redis Cluster specification suggests clients do not update
1186-
* their slot mapping for an ASK redirection, only for MOVED */
1187-
if (moved) c->redirections++;
1188-
11891185
/* Make sure we can parse the redirection host and port */
1190-
if (cluster_set_redirection(c,inbuf,moved) < 0) {
1191-
return -1;
1192-
}
1193-
1194-
/* We've been redirected */
1195-
return 1;
1196-
} else {
1197-
// Capture the error string Redis returned
1198-
cluster_set_err(c, inbuf, strlen(inbuf)-2);
1199-
return 0;
1186+
return !cluster_set_redirection(c, inbuf, moved) ? 1 : -1;
12001187
}
1188+
// Capture the error string Redis returned
1189+
cluster_set_err(c, inbuf, strlen(inbuf)-2);
1190+
return 0;
12011191
}
12021192

12031193
// Fetch the first line of our response from Redis.
@@ -1272,9 +1262,7 @@ static int cluster_dist_write(redisCluster *c, const char *cmd, size_t sz,
12721262

12731263
/* If we're not on the master, attempt to send the READONLY command to
12741264
* this slave, and skip it if that fails */
1275-
if (nodes[i] == 0 || redis_sock->readonly ||
1276-
cluster_send_readonly(redis_sock) == 0)
1277-
{
1265+
if (nodes[i] == 0 || cluster_send_readonly(redis_sock) == 0) {
12781266
/* Attempt to send the command */
12791267
if (CLUSTER_SEND_PAYLOAD(redis_sock, cmd, sz)) {
12801268
c->cmd_sock = redis_sock;
@@ -1567,7 +1555,7 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
15671555
* CLUSTERDOWN state from Redis Cluster. */
15681556
do {
15691557
/* Send MULTI to the socket if we're in MULTI mode but haven't yet */
1570-
if (c->flags->mode == MULTI && CMD_SOCK(c)->mode != MULTI) {
1558+
if (c->flags->mode == MULTI && c->cmd_sock->mode != MULTI) {
15711559
/* We have to fail if we can't send MULTI to the node */
15721560
if (cluster_send_multi(c, slot) == -1) {
15731561
CLUSTER_THROW_EXCEPTION("Unable to enter MULTI mode on requested slot", 0);
@@ -2975,26 +2963,22 @@ PHP_REDIS_API redisCachedCluster *cluster_cache_load(zend_string *hash) {
29752963

29762964
if (le != NULL) {
29772965
/* Sanity check on our list type */
2978-
if (le->type != le_cluster_slot_cache) {
2979-
php_error_docref(0, E_WARNING, "Invalid slot cache resource");
2980-
return NULL;
2966+
if (le->type == le_cluster_slot_cache) {
2967+
/* Success, return the cached entry */
2968+
return le->ptr;
29812969
}
2982-
2983-
/* Success, return the cached entry */
2984-
return le->ptr;
2970+
php_error_docref(0, E_WARNING, "Invalid slot cache resource");
29852971
}
29862972

29872973
/* Not found */
29882974
return NULL;
29892975
}
29902976

29912977
/* Cache a cluster's slot information in persistent_list if it's enabled */
2992-
PHP_REDIS_API int cluster_cache_store(zend_string *hash, HashTable *nodes) {
2978+
PHP_REDIS_API void cluster_cache_store(zend_string *hash, HashTable *nodes) {
29932979
redisCachedCluster *cc = cluster_cache_create(hash, nodes);
29942980

29952981
redis_register_persistent_resource(cc->hash, cc, le_cluster_slot_cache);
2996-
2997-
return SUCCESS;
29982982
}
29992983

30002984

cluster_library.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
#define SLOT_STREAM(c,s) (SLOT_SOCK(c,s)->stream)
4242
#define SLOT_SLAVES(c,s) (c->master[s]->slaves)
4343

44-
/* Macros to access socket and stream for the node we're communicating with */
45-
#define CMD_SOCK(c) (c->cmd_sock)
46-
#define CMD_STREAM(c) (c->cmd_sock->stream)
47-
4844
/* Compare redirection slot information with the passed node */
4945
#define CLUSTER_REDIR_CMP(c, sock) \
5046
(sock->port != c->redir_port || \
@@ -374,7 +370,6 @@ PHP_REDIS_API void cluster_disconnect(redisCluster *c, int force);
374370
PHP_REDIS_API int cluster_send_exec(redisCluster *c, short slot);
375371
PHP_REDIS_API int cluster_send_discard(redisCluster *c, short slot);
376372
PHP_REDIS_API int cluster_abort_exec(redisCluster *c);
377-
PHP_REDIS_API int cluster_reset_multi(redisCluster *c);
378373

379374
PHP_REDIS_API short cluster_find_slot(redisCluster *c, const char *host,
380375
unsigned short port);
@@ -397,7 +392,7 @@ PHP_REDIS_API void cluster_init_cache(redisCluster *c, redisCachedCluster *rcc);
397392

398393
PHP_REDIS_API char **cluster_sock_read_multibulk_reply(RedisSock *redis_sock, int *len);
399394

400-
PHP_REDIS_API int cluster_cache_store(zend_string *hash, HashTable *nodes);
395+
PHP_REDIS_API void cluster_cache_store(zend_string *hash, HashTable *nodes);
401396
PHP_REDIS_API redisCachedCluster *cluster_cache_load(zend_string *hash);
402397

403398
/*

0 commit comments

Comments
 (0)