@@ -2523,38 +2523,41 @@ int redis_restore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
25232523 return SUCCESS ;
25242524}
25252525
2526- /* BITPOS */
2526+ /* BITPOS key bit [start [end [BYTE | BIT]]] */
25272527int redis_bitpos_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
25282528 char * * cmd , int * cmd_len , short * slot , void * * ctx )
25292529{
2530- char * key ;
2531- int argc ;
2532- zend_long bit , start , end ;
2533- size_t key_len ;
2530+ zend_long start = 0 , end = -1 ;
2531+ zend_bool bit = 0 , bybit = 0 ;
2532+ smart_string cmdstr = { 0 } ;
2533+ zend_string * key = NULL ;
25342534
2535- argc = ZEND_NUM_ARGS ();
2536- if (zend_parse_parameters (argc , "sl|ll" , & key , & key_len , & bit ,
2537- & start , & end ) == FAILURE )
2538- {
2539- return FAILURE ;
2540- }
2535+ ZEND_PARSE_PARAMETERS_START (2 , 5 )
2536+ Z_PARAM_STR (key )
2537+ Z_PARAM_BOOL (bit )
2538+ Z_PARAM_OPTIONAL
2539+ Z_PARAM_LONG (start )
2540+ Z_PARAM_LONG (end )
2541+ Z_PARAM_BOOL (bybit )
2542+ ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
25412543
2542- // Prevalidate bit
2543- if (bit != 0 && bit != 1 ) {
2544- return FAILURE ;
2545- }
2544+ REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , 2 + (ZEND_NUM_ARGS () > 2 ? 2 : 0 ) + !!bybit , "BITPOS ");
25462545
2547- // Construct command based on arg count
2548- if (argc == 2 ) {
2549- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "BITPOS" , "kd" , key , key_len , bit );
2550- } else if (argc == 3 ) {
2551- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "BITPOS" , "kdd" , key , key_len , bit ,
2552- start );
2553- } else {
2554- * cmd_len = REDIS_CMD_SPPRINTF (cmd , "BITPOS" , "kddd" , key , key_len , bit ,
2555- start , end );
2546+ redis_cmd_append_sstr_key_zstr (& cmdstr , key , redis_sock , slot );
2547+ redis_cmd_append_sstr_long (& cmdstr , bit ) ;
2548+
2549+ /* Start and length if we were passed either */
2550+ if (ZEND_NUM_ARGS () > 2 ) {
2551+ redis_cmd_append_sstr_long (& cmdstr , start );
2552+ redis_cmd_append_sstr_long (& cmdstr , end );
25562553 }
25572554
2555+ /* Finally, BIT or BYTE if we were passed that argument */
2556+ REDIS_CMD_APPEND_SSTR_OPT_STATIC (& cmdstr , !!bybit , "BIT" );
2557+
2558+ * cmd = cmdstr .c ;
2559+ * cmd_len = cmdstr .len ;
2560+
25582561 return SUCCESS ;
25592562}
25602563
0 commit comments