@@ -286,6 +286,29 @@ redis_error_throw(RedisSock *redis_sock)
286
286
}
287
287
}
288
288
289
+ static int
290
+ read_mbulk_header (RedisSock * redis_sock , int * nelem )
291
+ {
292
+ char line [4096 ];
293
+ size_t len ;
294
+
295
+ /* Throws exception on failure */
296
+ if (redis_sock_gets (redis_sock , line , sizeof (line ) - 1 , & len ) < 0 ) {
297
+ return FAILURE ;
298
+ }
299
+
300
+ if (* line != TYPE_MULTIBULK ) {
301
+ if (* line == TYPE_ERR ) {
302
+ redis_sock_set_err (redis_sock , line + 1 , len - 1 );
303
+ }
304
+ return FAILURE ;
305
+ }
306
+
307
+ * nelem = atoi (line + 1 );
308
+
309
+ return SUCCESS ;
310
+ }
311
+
289
312
PHP_REDIS_API int
290
313
redis_check_eof (RedisSock * redis_sock , zend_bool no_retry , zend_bool no_throw )
291
314
{
@@ -561,22 +584,13 @@ PHP_REDIS_API zval *
561
584
redis_sock_read_multibulk_reply_zval (INTERNAL_FUNCTION_PARAMETERS ,
562
585
RedisSock * redis_sock , zval * z_tab )
563
586
{
564
- char inbuf [4096 ];
565
587
int numElems ;
566
- size_t len ;
567
588
568
- ZVAL_NULL (z_tab );
569
- if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len ) < 0 ) {
570
- return NULL ;
571
- }
572
-
573
- if (inbuf [0 ] != '*' ) {
589
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
590
+ ZVAL_NULL (z_tab );
574
591
return NULL ;
575
592
}
576
- numElems = atoi (inbuf + 1 );
577
-
578
593
array_init (z_tab );
579
-
580
594
redis_mbulk_reply_loop (redis_sock , z_tab , numElems , UNSERIALIZE_ALL );
581
595
582
596
return z_tab ;
@@ -1461,59 +1475,21 @@ static void array_zip_values_and_scores(RedisSock *redis_sock, zval *z_tab,
1461
1475
ZVAL_ZVAL (z_tab , & z_ret , 0 , 0 );
1462
1476
}
1463
1477
1464
- static int
1465
- read_mbulk_header (RedisSock * redis_sock , int * nelem )
1466
- {
1467
- char line [4096 ];
1468
- size_t len ;
1469
-
1470
- /* Throws exception on failure */
1471
- if (redis_sock_gets (redis_sock , line , sizeof (line )- 1 , & len ) < 0 )
1472
- return -1 ;
1473
-
1474
- if (line [0 ] != '*' ) {
1475
- if (IS_ATOMIC (redis_sock )) {
1476
- if (line [0 ] == '-' ) {
1477
- redis_sock_set_err (redis_sock , line + 1 , len - 1 );
1478
- }
1479
- }
1480
- return -1 ;
1481
- }
1482
-
1483
- * nelem = atoi (line + 1 );
1484
-
1485
- return 0 ;
1486
- }
1487
1478
1488
1479
static int
1489
1480
redis_mbulk_reply_zipped (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
1490
1481
zval * z_tab , int unserialize , int decode )
1491
1482
{
1492
- char inbuf [4096 ];
1493
1483
int numElems ;
1494
- size_t len ;
1495
1484
1496
- if (redis_sock_gets (redis_sock , inbuf , sizeof ( inbuf ) - 1 , & len ) < 0 ) {
1485
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
1497
1486
if (IS_ATOMIC (redis_sock )) {
1498
1487
RETVAL_FALSE ;
1499
1488
} else {
1500
1489
add_next_index_bool (z_tab , 0 );
1501
1490
}
1502
1491
return FAILURE ;
1503
1492
}
1504
-
1505
- if (inbuf [0 ] != '*' ) {
1506
- if (IS_ATOMIC (redis_sock )) {
1507
- RETVAL_FALSE ;
1508
- } else {
1509
- add_next_index_bool (z_tab , 0 );
1510
- }
1511
- if (* inbuf == TYPE_ERR ) {
1512
- redis_sock_set_err (redis_sock , inbuf + 1 , len - 1 );
1513
- }
1514
- return -1 ;
1515
- }
1516
- numElems = atoi (inbuf + 1 );
1517
1493
zval z_multi_result ;
1518
1494
array_init (& z_multi_result ); /* pre-allocate array for multi's results. */
1519
1495
@@ -1552,6 +1528,11 @@ redis_geosearch_response(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
1552
1528
zend_string * zkey ;
1553
1529
1554
1530
if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
1531
+ if (IS_ATOMIC (redis_sock )) {
1532
+ RETVAL_FALSE ;
1533
+ } else {
1534
+ add_next_index_bool (z_tab , 0 );
1535
+ }
1555
1536
return FAILURE ;
1556
1537
}
1557
1538
@@ -2614,28 +2595,16 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
2614
2595
void * ctx )
2615
2596
{
2616
2597
zval z_multi_result ;
2617
- char inbuf [4096 ];
2618
2598
int numElems ;
2619
- size_t len ;
2620
2599
2621
- if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len ) < 0 ) {
2622
- return -1 ;
2623
- }
2624
-
2625
- if (inbuf [0 ] != '*' ) {
2600
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
2626
2601
if (IS_ATOMIC (redis_sock )) {
2627
- if (inbuf [0 ] == '-' ) {
2628
- redis_sock_set_err (redis_sock , inbuf + 1 , len );
2629
- }
2630
2602
RETVAL_FALSE ;
2631
2603
} else {
2632
2604
add_next_index_bool (z_tab , 0 );
2633
2605
}
2634
- return -1 ;
2606
+ return FAILURE ;
2635
2607
}
2636
-
2637
- numElems = atoi (inbuf + 1 );
2638
-
2639
2608
if (numElems == -1 && redis_sock -> null_mbulk_as_null ) {
2640
2609
ZVAL_NULL (& z_multi_result );
2641
2610
} else {
@@ -2657,31 +2626,16 @@ PHP_REDIS_API int redis_sock_read_multibulk_reply(INTERNAL_FUNCTION_PARAMETERS,
2657
2626
PHP_REDIS_API int
2658
2627
redis_mbulk_reply_raw (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
2659
2628
{
2660
- char inbuf [4096 ];
2661
2629
int numElems ;
2662
- size_t len ;
2663
2630
2664
- if (redis_sock_gets (redis_sock , inbuf , sizeof ( inbuf ) - 1 , & len ) < 0 ) {
2631
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
2665
2632
if (IS_ATOMIC (redis_sock )) {
2666
2633
RETVAL_FALSE ;
2667
2634
} else {
2668
2635
add_next_index_bool (z_tab , 0 );
2669
2636
}
2670
2637
return FAILURE ;
2671
2638
}
2672
-
2673
- if (inbuf [0 ] != '*' ) {
2674
- if (IS_ATOMIC (redis_sock )) {
2675
- if (inbuf [0 ] == '-' ) {
2676
- redis_sock_set_err (redis_sock , inbuf + 1 , len );
2677
- }
2678
- RETVAL_FALSE ;
2679
- } else {
2680
- add_next_index_bool (z_tab , 0 );
2681
- }
2682
- return -1 ;
2683
- }
2684
- numElems = atoi (inbuf + 1 );
2685
2639
zval z_multi_result ;
2686
2640
array_init (& z_multi_result ); /* pre-allocate array for multi's results. */
2687
2641
@@ -2693,33 +2647,24 @@ redis_mbulk_reply_raw(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval
2693
2647
add_next_index_zval (z_tab , & z_multi_result );
2694
2648
}
2695
2649
2696
- return 0 ;
2650
+ return SUCCESS ;
2697
2651
}
2698
2652
2699
2653
PHP_REDIS_API int
2700
2654
redis_mbulk_reply_double (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
2701
2655
{
2702
- char inbuf [ 4096 ], * line ;
2656
+ char * line ;
2703
2657
int i , numElems , len ;
2704
- size_t buf_len ;
2705
2658
zval z_multi_result ;
2706
2659
2707
- if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & buf_len ) < 0 ) {
2708
- return FAILURE ;
2709
- }
2710
-
2711
- if (* inbuf != TYPE_MULTIBULK ) {
2660
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
2712
2661
if (IS_ATOMIC (redis_sock )) {
2713
- if (* inbuf == TYPE_ERR ) {
2714
- redis_sock_set_err (redis_sock , inbuf + 1 , buf_len );
2715
- }
2716
2662
RETVAL_FALSE ;
2717
2663
} else {
2718
2664
add_next_index_bool (z_tab , 0 );
2719
2665
}
2720
2666
return FAILURE ;
2721
2667
}
2722
- numElems = atoi (inbuf + 1 );
2723
2668
2724
2669
array_init (& z_multi_result );
2725
2670
for (i = 0 ; i < numElems ; ++ i ) {
@@ -2825,29 +2770,20 @@ redis_mbulk_reply_zipped_raw_variant(RedisSock *redis_sock, zval *zret, int coun
2825
2770
* keys with their returned values */
2826
2771
PHP_REDIS_API int redis_mbulk_reply_assoc (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , zval * z_tab , void * ctx )
2827
2772
{
2828
- char inbuf [ 4096 ], * response ;
2773
+ char * response ;
2829
2774
int response_len ;
2830
2775
int i , numElems ;
2831
- size_t len ;
2832
2776
2833
2777
zval * z_keys = ctx ;
2834
2778
2835
- if (redis_sock_gets (redis_sock , inbuf , sizeof (inbuf ) - 1 , & len ) < 0 ) {
2836
- goto failure ;
2837
- }
2838
-
2839
- if (* inbuf != TYPE_MULTIBULK ) {
2779
+ if (read_mbulk_header (redis_sock , & numElems ) < 0 ) {
2840
2780
if (IS_ATOMIC (redis_sock )) {
2841
2781
RETVAL_FALSE ;
2842
2782
} else {
2843
2783
add_next_index_bool (z_tab , 0 );
2844
2784
}
2845
- if (* inbuf == TYPE_ERR ) {
2846
- redis_sock_set_err (redis_sock , inbuf + 1 , len - 1 );
2847
- }
2848
2785
goto failure ;
2849
2786
}
2850
- numElems = atoi (inbuf + 1 );
2851
2787
zval z_multi_result ;
2852
2788
array_init (& z_multi_result ); /* pre-allocate array for multi's results. */
2853
2789
0 commit comments