@@ -270,10 +270,7 @@ static int cluster_send_direct(RedisSock *redis_sock, char *cmd, int cmd_len,
270270{
271271 char buf [1024 ];
272272
273- /* Connect to the socket if we aren't yet */
274- CLUSTER_LAZY_CONNECT (redis_sock );
275-
276- /* Send our command, validate the reply type, and consume the first line */
273+ /* Connect to the socket if we aren't yet and send our command, validate the reply type, and consume the first line */
277274 if (!CLUSTER_SEND_PAYLOAD (redis_sock ,cmd ,cmd_len ) ||
278275 !CLUSTER_VALIDATE_REPLY_TYPE (redis_sock , type ) ||
279276 !php_stream_gets (redis_sock -> stream , buf , sizeof (buf ))) return -1 ;
@@ -1088,7 +1085,6 @@ PHP_REDIS_API void cluster_disconnect(redisCluster *c, int force TSRMLS_DC) {
10881085 ZEND_HASH_FOREACH_PTR (c -> nodes , node ) {
10891086 if (node == NULL ) continue ;
10901087 redis_sock_disconnect (node -> sock , force TSRMLS_CC );
1091- node -> sock -> lazy_connect = 1 ;
10921088 } ZEND_HASH_FOREACH_END ();
10931089}
10941090
@@ -1124,7 +1120,9 @@ static int cluster_dist_write(redisCluster *c, const char *cmd, size_t sz,
11241120 if (!redis_sock ) continue ;
11251121
11261122 /* Connect to this node if we haven't already */
1127- CLUSTER_LAZY_CONNECT (redis_sock );
1123+ if (redis_sock_server_open (redis_sock TSRMLS_CC )) {
1124+ continue ;
1125+ }
11281126
11291127 /* If we're not on the master, attempt to send the READONLY command to
11301128 * this slave, and skip it if that fails */
@@ -1200,11 +1198,9 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
12001198 * at random. */
12011199 if (failover == REDIS_FAILOVER_NONE ) {
12021200 /* Success if we can send our payload to the master */
1203- CLUSTER_LAZY_CONNECT (redis_sock );
12041201 if (CLUSTER_SEND_PAYLOAD (redis_sock , cmd , sz )) return 0 ;
12051202 } else if (failover == REDIS_FAILOVER_ERROR ) {
12061203 /* Try the master, then fall back to any slaves we may have */
1207- CLUSTER_LAZY_CONNECT (redis_sock );
12081204 if (CLUSTER_SEND_PAYLOAD (redis_sock , cmd , sz ) ||
12091205 !cluster_dist_write (c , cmd , sz , 1 TSRMLS_CC )) return 0 ;
12101206 } else {
@@ -1225,10 +1221,7 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
12251221 /* Skip this node if it's the one that failed, or if it's a slave */
12261222 if (seed_node == NULL || seed_node -> sock == redis_sock || seed_node -> slave ) continue ;
12271223
1228- /* Connect to this node if we haven't already */
1229- CLUSTER_LAZY_CONNECT (seed_node -> sock );
1230-
1231- /* Attempt to write our request to this node */
1224+ /* Connect to this node if we haven't already and attempt to write our request to this node */
12321225 if (CLUSTER_SEND_PAYLOAD (seed_node -> sock , cmd , sz )) {
12331226 c -> cmd_slot = seed_node -> slot ;
12341227 c -> cmd_sock = seed_node -> sock ;
@@ -1456,6 +1449,9 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
14561449 "The Redis Cluster is down (CLUSTERDOWN)" , 0 TSRMLS_CC );
14571450 return -1 ;
14581451 } else if (timedout ) {
1452+ // Make sure the socket is reconnected, it such that it is in a clean state
1453+ redis_sock_disconnect (c -> cmd_sock , 1 TSRMLS_CC );
1454+
14591455 zend_throw_exception (redis_cluster_exception_ce ,
14601456 "Timed out attempting to find data in the correct node!" , 0 TSRMLS_CC );
14611457 }
0 commit comments