@@ -2411,7 +2411,7 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
2411
2411
{
2412
2412
redisCluster * c = GET_CONTEXT ();
2413
2413
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 ;
2415
2415
int cmd_len , key_free = 0 ;
2416
2416
short slot ;
2417
2417
zval * z_it ;
@@ -2450,6 +2450,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
2450
2450
key_free = redis_key_prefix (c -> flags , & key , & key_len );
2451
2451
slot = cluster_hash_key (key , key_len );
2452
2452
2453
+ if (c -> flags -> scan & REDIS_SCAN_PREFIX ) {
2454
+ pat_free = redis_key_prefix (c -> flags , & pat , & pat_len );
2455
+ }
2456
+
2453
2457
// If SCAN_RETRY is set, loop until we get a zero iterator or until
2454
2458
// we get non-zero elements. Otherwise we just send the command once.
2455
2459
do {
@@ -2488,7 +2492,10 @@ static void cluster_kscan_cmd(INTERNAL_FUNCTION_PARAMETERS,
2488
2492
2489
2493
// Free our command
2490
2494
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 );
2492
2499
2493
2500
// Free our key
2494
2501
if (key_free ) efree (key );
@@ -2505,7 +2512,7 @@ PHP_METHOD(RedisCluster, scan) {
2505
2512
int cmd_len ;
2506
2513
short slot ;
2507
2514
zval * z_it , * z_node ;
2508
- long it , num_ele ;
2515
+ long it , num_ele , pat_free = 0 ;
2509
2516
zend_long count = 0 ;
2510
2517
2511
2518
/* Treat as read-only */
@@ -2534,6 +2541,10 @@ PHP_METHOD(RedisCluster, scan) {
2534
2541
RETURN_FALSE ;
2535
2542
}
2536
2543
2544
+ if (c -> flags -> scan & REDIS_SCAN_PREFIX ) {
2545
+ pat_free = redis_key_prefix (c -> flags , & pat , & pat_len );
2546
+ }
2547
+
2537
2548
/* With SCAN_RETRY on, loop until we get some keys, otherwise just return
2538
2549
* what Redis does, as it does */
2539
2550
do {
@@ -2570,7 +2581,9 @@ PHP_METHOD(RedisCluster, scan) {
2570
2581
efree (cmd );
2571
2582
2572
2583
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 );
2574
2587
2575
2588
Z_LVAL_P (z_it ) = it ;
2576
2589
}
0 commit comments