@@ -495,17 +495,24 @@ int redis_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
495495}
496496
497497/* ZRANGEBYSCORE/ZREVRANGEBYSCORE */
498+ #define IS_WITHSCORES_ARG (s , l ) \
499+ (l == sizeof("withscores") && !strncasecmp(s,"withscores",sizeof("withscores")))
500+ #define IS_LIMIT_ARG (s , l ) \
501+ (l == sizeof("limit") && !strncasecmp(s,"limit",sizeof("limit")))
502+
498503int redis_zrangebyscore_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
499504 char * kw , char * * cmd , int * cmd_len , int * withscores ,
500505 short * slot , void * * ctx )
501506{
502507 char * key ;
503508 int key_len , key_free ;
504- char * start , * end ;
509+ char * start , * end , * optkey ;
505510 int start_len , end_len ;
506- int has_limit = 0 ;
511+ int has_limit = 0 , type ;
507512 long limit_low , limit_high ;
508513 zval * z_opt = NULL , * * z_ele ;
514+ unsigned long idx ;
515+ unsigned int optlen ;
509516 HashTable * ht_opt ;
510517
511518 if (zend_parse_parameters (ZEND_NUM_ARGS () TSRMLS_CC , "sss|a" , & key , & key_len ,
@@ -518,26 +525,34 @@ int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
518525 // Check for an options array
519526 if (z_opt && Z_TYPE_P (z_opt )== IS_ARRAY ) {
520527 ht_opt = Z_ARRVAL_P (z_opt );
521-
522- // Check for WITHSCORES
523- * withscores = (zend_hash_find (ht_opt ,"withscores" ,sizeof ("withscores" ),
524- (void * * )& z_ele )== SUCCESS && Z_TYPE_PP (z_ele )== IS_BOOL &&
525- Z_BVAL_PP (z_ele )== 1 );
526-
527- // LIMIT
528- if (zend_hash_find (ht_opt ,"limit" ,sizeof ("limit" ),(void * * )& z_ele )
529- == SUCCESS )
528+ for (zend_hash_internal_pointer_reset (ht_opt );
529+ zend_hash_has_more_elements (ht_opt ) == SUCCESS ;
530+ zend_hash_move_forward (ht_opt ))
530531 {
531- HashTable * ht_limit = Z_ARRVAL_PP (z_ele );
532- zval * * z_off , * * z_cnt ;
533- if (zend_hash_index_find (ht_limit ,0 ,(void * * )& z_off )== SUCCESS &&
534- zend_hash_index_find (ht_limit ,1 ,(void * * )& z_cnt )== SUCCESS &&
535- Z_TYPE_PP (z_off )== IS_LONG && Z_TYPE_PP (z_cnt )== IS_LONG )
536- {
537- has_limit = 1 ;
538- limit_low = Z_LVAL_PP (z_off );
539- limit_high = Z_LVAL_PP (z_cnt );
540- }
532+ /* Grab current key and value */
533+ type = zend_hash_get_current_key_ex (ht_opt , & optkey , & optlen , & idx , 0 , NULL );
534+ zend_hash_get_current_data (ht_opt , (void * * )& z_ele );
535+
536+ /* All options require a string key type */
537+ if (type != HASH_KEY_IS_STRING ) continue ;
538+
539+ /* Check for withscores and limit */
540+ if (IS_WITHSCORES_ARG (optkey , optlen )) {
541+ * withscores = Z_TYPE_PP (z_ele )== IS_BOOL && Z_BVAL_PP (z_ele )== 1 ;
542+ } else if (IS_LIMIT_ARG (optkey , optlen ) &&
543+ Z_TYPE_PP (z_ele ) == IS_ARRAY )
544+ {
545+ HashTable * htlimit = Z_ARRVAL_PP (z_ele );
546+ zval * * zoff , * * zcnt ;
547+ if (zend_hash_index_find (htlimit ,0 ,(void * * )& zoff )== SUCCESS &&
548+ zend_hash_index_find (htlimit ,1 ,(void * * )& zcnt )== SUCCESS &&
549+ Z_TYPE_PP (zoff ) == IS_LONG && Z_TYPE_PP (zcnt ) == IS_LONG )
550+ {
551+ has_limit = 1 ;
552+ limit_low = Z_LVAL_PP (zoff );
553+ limit_high = Z_LVAL_PP (zcnt );
554+ }
555+ }
541556 }
542557 }
543558
0 commit comments