@@ -1775,19 +1775,16 @@ gen_vararg_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
17751775{
17761776 smart_string cmdstr = {0 };
17771777 zval * argv = NULL ;
1778- zend_string * arg ;
17791778 int argc = 0 ;
17801779
17811780 ZEND_PARSE_PARAMETERS_START (min_argc , -1 )
17821781 Z_PARAM_VARIADIC ('*' , argv , argc )
17831782 ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
17841783
1785- redis_cmd_init_sstr (& cmdstr , ZEND_NUM_ARGS () , kw , strlen (kw ));
1784+ redis_cmd_init_sstr (& cmdstr , argc , kw , strlen (kw ));
17861785
17871786 for (uint32_t i = 0 ; i < argc ; i ++ ) {
1788- arg = zval_get_string (& argv [i ]);
1789- redis_cmd_append_sstr_zstr (& cmdstr , arg );
1790- zend_string_release (arg );
1787+ redis_cmd_append_sstr_zval (& cmdstr , & argv [i ], NULL );
17911788 }
17921789
17931790 * cmd = cmdstr .c ;
@@ -1804,8 +1801,6 @@ int redis_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
18041801 HashTable * kvals = NULL ;
18051802 zend_string * key ;
18061803 zend_ulong idx ;
1807- char buf [64 ];
1808- size_t klen ;
18091804 zval * zv ;
18101805
18111806 ZEND_PARSE_PARAMETERS_START (1 , 1 )
@@ -1818,14 +1813,12 @@ int redis_mset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
18181813 redis_cmd_init_sstr (& cmdstr , zend_hash_num_elements (kvals ) * 2 , kw , strlen (kw ));
18191814
18201815 ZEND_HASH_FOREACH_KEY_VAL (kvals , idx , key , zv ) {
1816+ ZVAL_DEREF (zv );
18211817 if (key ) {
18221818 redis_cmd_append_sstr_key_zstr (& cmdstr , key , redis_sock , NULL );
18231819 } else {
1824- klen = snprintf (buf , sizeof (buf ), ZEND_LONG_FMT , idx );
1825- redis_cmd_append_sstr_key (& cmdstr , buf , klen , redis_sock , NULL );
1820+ redis_cmd_append_sstr_key_long (& cmdstr , idx , redis_sock , NULL );
18261821 }
1827-
1828- ZVAL_DEREF (zv );
18291822 redis_cmd_append_sstr_zval (& cmdstr , zv , redis_sock );
18301823 } ZEND_HASH_FOREACH_END ();
18311824
@@ -1923,12 +1916,13 @@ static int gen_varkey_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
19231916int redis_mpop_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock , char * kw ,
19241917 char * * cmd , int * cmd_len , short * slot , void * * ctx )
19251918{
1926- zend_string * from = NULL , * key ;
19271919 int argc , blocking , is_zmpop ;
19281920 smart_string cmdstr = {0 };
1921+ zend_string * from = NULL ;
19291922 HashTable * keys = NULL ;
19301923 double timeout = 0.0 ;
19311924 zend_long count = 1 ;
1925+ short slot2 = -1 ;
19321926 zval * zv ;
19331927
19341928 /* Sanity check on our keyword */
@@ -1974,22 +1968,15 @@ int redis_mpop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw
19741968 if (slot ) * slot = -1 ;
19751969
19761970 ZEND_HASH_FOREACH_VAL (keys , zv ) {
1977- key = redis_key_prefix_zval (redis_sock , zv );
1978-
1971+ redis_cmd_append_sstr_key_zval (& cmdstr , zv , redis_sock , slot );
19791972 if (slot ) {
1980- if (* slot == -1 ) {
1981- * slot = cluster_hash_key_zstr (key );
1982- } else if (* slot != cluster_hash_key_zstr (key )) {
1973+ if (slot2 != -1 && * slot != slot2 ) {
19831974 php_error_docref (NULL , E_WARNING , "All keys don't hash to the same slot" );
1984- zend_string_release (key );
19851975 efree (cmdstr .c );
19861976 return FAILURE ;
19871977 }
1978+ slot2 = * slot ;
19881979 }
1989-
1990- redis_cmd_append_sstr_zstr (& cmdstr , key );
1991-
1992- zend_string_release (key );
19931980 } ZEND_HASH_FOREACH_END ();
19941981
19951982 redis_cmd_append_sstr_zstr (& cmdstr , from );
@@ -4224,10 +4211,6 @@ static int get_georadius_opts(HashTable *ht, geoOptions *opts) {
42244211void append_georadius_opts (RedisSock * redis_sock , smart_string * str , short * slot ,
42254212 geoOptions * opt )
42264213{
4227- char * key ;
4228- size_t keylen ;
4229- int keyfree ;
4230-
42314214 if (opt -> withcoord )
42324215 REDIS_CMD_APPEND_SSTR_STATIC (str , "WITHCOORD" );
42334216 if (opt -> withdist )
@@ -4253,21 +4236,13 @@ void append_georadius_opts(RedisSock *redis_sock, smart_string *str, short *slot
42534236
42544237 /* Append store options if we've got them */
42554238 if (opt -> store != STORE_NONE && opt -> key != NULL ) {
4256- /* Grab string bits and prefix if requested */
4257- key = ZSTR_VAL (opt -> key );
4258- keylen = ZSTR_LEN (opt -> key );
4259- keyfree = redis_key_prefix (redis_sock , & key , & keylen );
4260-
42614239 if (opt -> store == STORE_COORD ) {
42624240 REDIS_CMD_APPEND_SSTR_STATIC (str , "STORE" );
42634241 } else {
42644242 REDIS_CMD_APPEND_SSTR_STATIC (str , "STOREDIST" );
42654243 }
42664244
4267- redis_cmd_append_sstr (str , key , keylen );
4268-
4269- CMD_SET_SLOT (slot , key , keylen );
4270- if (keyfree ) free (key );
4245+ redis_cmd_append_sstr_key_zstr (str , opt -> key , redis_sock , slot );
42714246 }
42724247}
42734248
@@ -4276,55 +4251,47 @@ int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
42764251 char * kw , char * * cmd , int * cmd_len , short * slot ,
42774252 void * * ctx )
42784253{
4279- char * key , * unit ;
4280- short store_slot = 0 ;
4281- size_t keylen , unitlen ;
4282- int argc = 5 , keyfree ;
4283- double lng , lat , radius ;
4284- zval * opts = NULL ;
4285- geoOptions gopts = {0 };
4254+ zend_string * key = NULL , * unit = NULL ;
4255+ double lng = 0 , lat = 0 , radius = 0 ;
42864256 smart_string cmdstr = {0 };
4257+ HashTable * opts = NULL ;
4258+ geoOptions gopts = {0 };
4259+ short store_slot = -1 ;
4260+ uint32_t argc ;
42874261
4288- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sddds|a" , & key , & keylen ,
4289- & lng , & lat , & radius , & unit , & unitlen , & opts )
4290- == FAILURE )
4291- {
4292- return FAILURE ;
4293- }
4262+ ZEND_PARSE_PARAMETERS_START (5 , 6 )
4263+ Z_PARAM_STR (key )
4264+ Z_PARAM_DOUBLE (lng )
4265+ Z_PARAM_DOUBLE (lat )
4266+ Z_PARAM_DOUBLE (radius )
4267+ Z_PARAM_STR (unit )
4268+ Z_PARAM_OPTIONAL
4269+ Z_PARAM_ARRAY_HT_OR_NULL (opts )
4270+ ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
42944271
42954272 /* Parse any GEORADIUS options we have */
4296- if (opts != NULL ) {
4297- /* Attempt to parse our options array */
4298- if (get_georadius_opts (Z_ARRVAL_P (opts ), & gopts ) != SUCCESS )
4299- {
4300- return FAILURE ;
4301- }
4302- }
4273+ if (opts != NULL && get_georadius_opts (opts , & gopts ) != SUCCESS )
4274+ return FAILURE ;
43034275
43044276 /* Increment argc depending on options */
4305- argc += gopts .withcoord + gopts .withdist + gopts .withhash +
4306- (gopts .sort != SORT_NONE ) + (gopts .count ? 2 + gopts .any : 0 ) +
4307- (gopts .store != STORE_NONE ? 2 : 0 );
4277+ argc = 5 + gopts .withcoord + gopts .withdist + gopts .withhash +
4278+ (gopts .sort != SORT_NONE ) + (gopts .count ? 2 + gopts .any : 0 ) +
4279+ (gopts .store != STORE_NONE ? 2 : 0 );
43084280
43094281 /* Begin construction of our command */
43104282 redis_cmd_init_sstr (& cmdstr , argc , kw , strlen (kw ));
4311-
4312- /* Prefix and set slot */
4313- keyfree = redis_key_prefix (redis_sock , & key , & keylen );
4314- CMD_SET_SLOT (slot , key , keylen );
4283+ redis_cmd_append_sstr_key_zstr (& cmdstr , key , redis_sock , slot );
43154284
43164285 /* Append required arguments */
4317- redis_cmd_append_sstr (& cmdstr , key , keylen );
43184286 redis_cmd_append_sstr_dbl (& cmdstr , lng );
43194287 redis_cmd_append_sstr_dbl (& cmdstr , lat );
43204288 redis_cmd_append_sstr_dbl (& cmdstr , radius );
4321- redis_cmd_append_sstr (& cmdstr , unit , unitlen );
4289+ redis_cmd_append_sstr_zstr (& cmdstr , unit );
43224290
43234291 /* Append optional arguments */
43244292 append_georadius_opts (redis_sock , & cmdstr , slot ? & store_slot : NULL , & gopts );
43254293
43264294 /* Free key if it was prefixed */
4327- if (keyfree ) efree (key );
43284295 if (gopts .key ) zend_string_release (gopts .key );
43294296
43304297 /* Protect the user from CROSSSLOT if we're in cluster */
0 commit comments