From 224155ef6b39e8952a62150b3a399b6b64c7f293 Mon Sep 17 00:00:00 2001 From: michael-grunder Date: Thu, 26 Feb 2015 10:48:11 -0800 Subject: Use cluster_send_slot for EXEC as we'll want to capture the MULTI-BULK len, which isn't handled properly by cluster_send_direct. We can go through the normal logic chain, as neither MULTI or EXEC are marked as "readonly" commands, and therefore will only be delivered to master nodes. --- cluster_library.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'cluster_library.c') diff --git a/cluster_library.c b/cluster_library.c index 700e2c74..372d17c2 100644 --- a/cluster_library.c +++ b/cluster_library.c @@ -271,6 +271,9 @@ static int cluster_send_asking(RedisSock *redis_sock TSRMLS_DC) { sizeof(RESP_ASKING_CMD)-1, TYPE_LINE TSRMLS_CC); } +/* Send READONLY to a specific RedisSock unless it's already flagged as being + * in READONLY mode. If we can send the command, we flag the socket as being + * in that mode. */ static int cluster_send_readonly(RedisSock *redis_sock TSRMLS_DC) { int ret; @@ -288,6 +291,7 @@ static int cluster_send_readonly(RedisSock *redis_sock TSRMLS_DC) { return ret; } +/* 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) @@ -298,13 +302,13 @@ static int cluster_send_multi(redisCluster *c, short slot TSRMLS_DC) { return -1; } +/* Send EXEC to a given slot. We can use the normal command processing mechanism + * here because we know we'll only have sent MULTI to the master nodes. We can't + * failover inside a transaction, as we don't know if the transaction will only + * be readonly commands, or contain write commands as well */ PHPAPI int cluster_send_exec(redisCluster *c, short slot TSRMLS_DC) { - if (cluster_send_direct(SLOT_SOCK(c,slot), RESP_EXEC_CMD, - sizeof(RESP_EXEC_CMD)-1, TYPE_MULTIBULK TSRMLS_CC)) - { - return c->reply_len; - } - return -1; + return cluster_send_slot(c, slot, RESP_EXEC_CMD, sizeof(RESP_EXEC_CMD)-1, + TYPE_MULTIBULK TSRMLS_CC); } PHPAPI int cluster_send_discard(redisCluster *c, short slot TSRMLS_DC) { -- cgit v1.2.3