@@ -1206,8 +1206,7 @@ static int cluster_set_redirection(redisCluster* c, char *msg, int moved)
12061206 * 
12071207 * This function will return -1 on a critical error (e.g. parse/communication 
12081208 * error, 0 if no redirection was encountered, and 1 if the data was moved. */ 
1209- static  int  cluster_check_response (redisCluster  * c , REDIS_REPLY_TYPE  * reply_type 
1210-                                  )
1209+ static  int  cluster_check_response (redisCluster  * c , REDIS_REPLY_TYPE  * reply_type )
12111210{
12121211    size_t  sz ;
12131212
@@ -1232,15 +1231,17 @@ static int cluster_check_response(redisCluster *c, REDIS_REPLY_TYPE *reply_type
12321231        }
12331232
12341233        // Check for MOVED or ASK redirection 
1235-         if  ((moved  =  IS_MOVED (inbuf )) ||  IS_ASK (inbuf )) { // Set our redirection information 
1236-             /* We'll want to invalidate slot cache if we're using one */ 
1237-             c -> redirections ++ ;
1234+         if  ((moved  =  IS_MOVED (inbuf )) ||  IS_ASK (inbuf )) {
1235+             /* The Redis Cluster specification suggests clients do not update 
1236+              * their slot mapping for an ASK redirection, only for MOVED */ 
1237+             if  (moved ) c -> redirections ++ ;
12381238
1239+             /* Make sure we can parse the redirection host and port */ 
12391240            if  (cluster_set_redirection (c ,inbuf ,moved ) <  0 ) {
12401241                return  -1 ;
12411242            }
12421243
1243-             // Data moved  
1244+             /* We've been redirected */  
12441245            return  1 ;
12451246        } else  {
12461247            // Capture the error string Redis returned 
@@ -1380,8 +1381,7 @@ static int cluster_sock_write(redisCluster *c, const char *cmd, size_t sz,
13801381    /* If in ASK redirection, get/create the node for that host:port, otherwise 
13811382     * just use the command socket. */ 
13821383    if  (c -> redir_type  ==  REDIR_ASK ) {
1383-         redis_sock  =  cluster_get_asking_sock (c );
1384-         if  (cluster_send_asking (redis_sock ) <  0 ) {
1384+         if  (cluster_send_asking (c -> cmd_sock ) <  0 ) {
13851385            return  -1 ;
13861386        }
13871387    }
@@ -1627,10 +1627,13 @@ PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char
16271627               return  -1 ;
16281628           }
16291629
1630-            /* Update mapping if the data has MOVED */ 
16311630           if  (c -> redir_type  ==  REDIR_MOVED ) {
1631+                /* For MOVED redirection we want to update our cached mapping */ 
16321632               cluster_update_slot (c );
16331633               c -> cmd_sock  =  SLOT_SOCK (c , slot );
1634+            } else  if  (c -> redir_type  ==  REDIR_ASK ) {
1635+                /* For ASK redirection we want to redirect but not update slot mapping */ 
1636+                c -> cmd_sock  =  cluster_get_asking_sock (c );
16341637           }
16351638        }
16361639
0 commit comments