@@ -3163,89 +3163,46 @@ int redis_pfmerge_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
31633163int redis_pfcount_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
31643164 char * * cmd , int * cmd_len , short * slot , void * * ctx )
31653165{
3166- zval * z_keys , * z_key ;
3167- HashTable * ht_keys ;
31683166 smart_string cmdstr = {0 };
3169- int num_keys , key_free ;
3170- size_t key_len ;
3171- char * key ;
3172- short kslot = -1 ;
3173- zend_string * zstr ;
3167+ zval * zarg = NULL , * zv ;
3168+ short slot2 = -1 ;
3169+ uint32_t keys ;
31743170
3175- if (zend_parse_parameters (ZEND_NUM_ARGS (),"z" ,& z_keys ) == FAILURE ) {
3176- return FAILURE ;
3177- }
3178-
3179- /* If we were passed an array of keys, iterate through them prefixing if
3180- * required and capturing lengths and if we need to free them. Otherwise
3181- * attempt to treat the argument as a string and just pass one */
3182- if (Z_TYPE_P (z_keys ) == IS_ARRAY ) {
3183- /* Grab key hash table and the number of keys */
3184- ht_keys = Z_ARRVAL_P (z_keys );
3185- num_keys = zend_hash_num_elements (ht_keys );
3171+ ZEND_PARSE_PARAMETERS_START (1 , 1 )
3172+ Z_PARAM_ZVAL (zarg )
3173+ ZEND_PARSE_PARAMETERS_END_EX (return FAILURE );
31863174
3187- /* There is no reason to send zero keys */
3188- if (num_keys == 0 ) {
3175+ if (Z_TYPE_P (zarg ) == IS_STRING ) {
3176+ REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , 1 , "PFCOUNT" );
3177+ redis_cmd_append_sstr_key_zstr (& cmdstr , Z_STR_P (zarg ), redis_sock , slot );
3178+ } else if (Z_TYPE_P (zarg ) == IS_ARRAY ) {
3179+ keys = zend_hash_num_elements (Z_ARRVAL_P (zarg ));
3180+ if (keys == 0 )
31893181 return FAILURE ;
3190- }
31913182
3192- /* Initialize the command with our number of arguments */
3193- redis_cmd_init_sstr (& cmdstr , num_keys , ZEND_STRL ("PFCOUNT" ));
3183+ REDIS_CMD_INIT_SSTR_STATIC (& cmdstr , keys , "PFCOUNT" );
31943184
3195- /* Append our key(s) */
3196- ZEND_HASH_FOREACH_VAL (ht_keys , z_key ) {
3197- /* Turn our value into a string if it isn't one */
3198- zstr = zval_get_string (z_key );
3199- key = ZSTR_VAL (zstr );
3200- key_len = ZSTR_LEN (zstr );
3201-
3202- /* Append this key to our command */
3203- key_free = redis_key_prefix (redis_sock , & key , & key_len );
3204- redis_cmd_append_sstr (& cmdstr , key , key_len );
3205-
3206- /* Protect against CROSSLOT errors */
3185+ ZEND_HASH_FOREACH_VAL (Z_ARRVAL_P (zarg ), zv ) {
3186+ redis_cmd_append_sstr_key_zval (& cmdstr , zv , redis_sock , slot );
32073187 if (slot ) {
3208- if (kslot == -1 ) {
3209- kslot = cluster_hash_key (key , key_len );
3210- } else if (cluster_hash_key (key ,key_len )!= kslot ) {
3211- zend_string_release (zstr );
3212- if (key_free ) efree (key );
3213- efree (cmdstr .c );
3214-
3215- php_error_docref (NULL , E_WARNING ,
3216- "Not all keys hash to the same slot!" );
3217- return FAILURE ;
3218- }
3188+ if (slot2 != -1 && slot2 != * slot )
3189+ goto cross_slot ;
3190+ slot2 = * slot ;
32193191 }
3220-
3221- /* Cleanup */
3222- zend_string_release (zstr );
3223- if (key_free ) efree (key );
32243192 } ZEND_HASH_FOREACH_END ();
32253193 } else {
3226- /* Construct our whole command */
3227- redis_cmd_init_sstr (& cmdstr , 1 , ZEND_STRL ("PFCOUNT" ));
3228-
3229- /* Turn our key into a string if it's a different type */
3230- zstr = zval_get_string (z_keys );
3231- key = ZSTR_VAL (zstr );
3232- key_len = ZSTR_LEN (zstr );
3233- key_free = redis_key_prefix (redis_sock , & key , & key_len );
3234- redis_cmd_append_sstr (& cmdstr , key , key_len );
3235-
3236- /* Hash our key */
3237- CMD_SET_SLOT (slot , key , key_len );
3238-
3239- /* Cleanup */
3240- zend_string_release (zstr );
3241- if (key_free ) efree (key );
3194+ php_error_docref (NULL , E_WARNING , "Argument must be either an array or a string" );
3195+ return FAILURE ;
32423196 }
32433197
3244- /* Push our command and length to the caller */
32453198 * cmd = cmdstr .c ;
32463199 * cmd_len = cmdstr .len ;
3247-
32483200 return SUCCESS ;
3201+
3202+ cross_slot :
3203+ php_error_docref (NULL , E_WARNING , "Not all keys hash to the same slot!" );
3204+ efree (cmdstr .c );
3205+ return FAILURE ;
32493206}
32503207
32513208int redis_auth_cmd (INTERNAL_FUNCTION_PARAMETERS , RedisSock * redis_sock ,
0 commit comments