@@ -2411,7 +2411,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
24112411{
24122412 redisCluster * c = GET_CONTEXT ();
24132413 char * cmd , * pat = NULL , * key = NULL ;
2414- size_t key_len = 0 , pat_len = 0 ;
2414+ size_t key_len = 0 , pat_len = 0 , pat_free = 0 ;
24152415 int cmd_len , key_free = 0 ;
24162416 short slot ;
24172417 zval * z_it ;
@@ -2450,6 +2450,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
24502450 key_free = redis_key_prefix (c -> flags , & key , & key_len );
24512451 slot = cluster_hash_key (key , key_len );
24522452
2453+ if (c -> flags -> scan & REDIS_SCAN_PREFIX ) {
2454+ pat_free = redis_key_prefix (c -> flags , & pat , & pat_len );
2455+ }
2456+
24532457 // If SCAN_RETRY is set, loop until we get a zero iterator or until
24542458 // we get non-zero elements. Otherwise we just send the command once.
24552459 do {
@@ -2488,7 +2492,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
24882492
24892493 // Free our command
24902494 efree (cmd );
2491- } while (c -> flags -> scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0 );
2495+ } while (c -> flags -> scan & REDIS_SCAN_RETRY && it != 0 && num_ele == 0 );
2496+
2497+ // Free our pattern
2498+ if (pat_free ) efree (pat );
24922499
24932500 // Free our key
24942501 if (key_free ) efree (key );
@@ -2505,7 +2512,7 @@ PHP_METHOD(RedisCluster, scan) {
25052512 int cmd_len ;
25062513 short slot ;
25072514 zval * z_it , * z_node ;
2508- long it , num_ele ;
2515+ long it , num_ele , pat_free = 0 ;
25092516 zend_long count = 0 ;
25102517
25112518 /* Treat as read-only */
@@ -2534,6 +2541,10 @@ PHP_METHOD(RedisCluster, scan) {
25342541 RETURN_FALSE ;
25352542 }
25362543
2544+ if (c -> flags -> scan & REDIS_SCAN_PREFIX ) {
2545+ pat_free = redis_key_prefix (c -> flags , & pat , & pat_len );
2546+ }
2547+
25372548 /* With SCAN_RETRY on, loop until we get some keys, otherwise just return
25382549 * what Redis does, as it does */
25392550 do {
@@ -2570,7 +2581,9 @@ PHP_METHOD(RedisCluster, scan) {
25702581 efree (cmd );
25712582
25722583 num_ele = zend_hash_num_elements (Z_ARRVAL_P (return_value ));
2573- } while (c -> flags -> scan == REDIS_SCAN_RETRY && it != 0 && num_ele == 0 );
2584+ } while (c -> flags -> scan & REDIS_SCAN_RETRY && it != 0 && num_ele == 0 );
2585+
2586+ if (pat_free ) efree (pat );
25742587
25752588 Z_LVAL_P (z_it ) = it ;
25762589}
0 commit comments