@@ -4856,18 +4856,15 @@ PHP_METHOD(Redis, hMget) {
4856
4856
REDIS_PROCESS_RESPONSE_CLOSURE (redis_sock_read_multibulk_reply_assoc , z_keys );
4857
4857
}
4858
4858
4859
-
4860
4859
PHP_METHOD (Redis , hMset )
4861
4860
{
4862
4861
zval * object ;
4863
4862
RedisSock * redis_sock ;
4864
- char * key = NULL , * cmd ;
4865
- int key_len , cmd_len , key_free ;
4863
+ char * key = NULL , * cmd , * old_cmd = NULL ;
4864
+ int key_len , cmd_len , key_free , i , element_count = 2 ;
4866
4865
zval * z_hash ;
4867
4866
HashTable * ht_hash ;
4868
- int i ;
4869
- int element_count = 2 ;
4870
- char * old_cmd = NULL ;
4867
+ smart_str set_cmds = {0 };
4871
4868
4872
4869
if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Osa" ,
4873
4870
& object , redis_ce ,
@@ -4885,68 +4882,63 @@ PHP_METHOD(Redis, hMset)
4885
4882
RETURN_FALSE ;
4886
4883
}
4887
4884
4888
- key_free = redis_key_prefix (redis_sock , & key , & key_len TSRMLS_CC );
4889
- cmd_len = redis_cmd_format (& cmd ,
4885
+ key_free = redis_key_prefix (redis_sock , & key , & key_len TSRMLS_CC );
4886
+ cmd_len = redis_cmd_format (& cmd ,
4890
4887
"$5" _NL "HMSET" _NL
4891
4888
"$%d" _NL "%s" _NL
4892
4889
, key_len , key , key_len );
4893
- if (key_free ) efree (key );
4890
+ if (key_free ) efree (key );
4894
4891
4895
4892
/* looping on each item of the array */
4896
- for (i = 0 , zend_hash_internal_pointer_reset (ht_hash );
4897
- zend_hash_has_more_elements (ht_hash ) == SUCCESS ;
4898
- i ++ , zend_hash_move_forward (ht_hash )) {
4899
-
4900
- char * hkey ;
4901
- unsigned int hkey_len ;
4902
- unsigned long idx ;
4903
- int type ;
4904
- int hkey_free = 0 ;
4905
- zval * * z_value_p ;
4893
+ for (i = 0 , zend_hash_internal_pointer_reset (ht_hash );
4894
+ zend_hash_has_more_elements (ht_hash ) == SUCCESS ;
4895
+ i ++ , zend_hash_move_forward (ht_hash )) {
4896
+
4897
+ char * hkey , hkey_str [40 ];
4898
+ unsigned int hkey_len ;
4899
+ unsigned long idx ;
4900
+ int type ;
4901
+ zval * * z_value_p ;
4906
4902
4907
- char * hval ;
4903
+ char * hval ;
4908
4904
int hval_len , hval_free ;
4909
4905
4910
- type = zend_hash_get_current_key_ex (ht_hash , & hkey , & hkey_len , & idx , 0 , NULL );
4906
+ type = zend_hash_get_current_key_ex (ht_hash , & hkey , & hkey_len , & idx , 0 , NULL );
4911
4907
4912
- if (zend_hash_get_current_data (ht_hash , (void * * )& z_value_p ) == FAILURE ) {
4913
- continue ; /* this should never happen */
4914
- }
4908
+ if (zend_hash_get_current_data (ht_hash , (void * * )& z_value_p ) == FAILURE ) {
4909
+ continue ; /* this should never happen */
4910
+ }
4915
4911
4916
- if (type != HASH_KEY_IS_STRING ) { /* convert to string */
4917
- hkey_free = 1 ;
4918
- hkey = emalloc (40 );
4919
- hkey_len = 1 + sprintf (hkey , "%ld" , idx );
4912
+ if (type != HASH_KEY_IS_STRING ) { /* convert to string */
4913
+ hkey_len = 1 + sprintf (hkey_str , "%ld" , idx );
4914
+ hkey = (char * )hkey_str ;
4920
4915
}
4921
4916
element_count += 2 ;
4922
4917
4923
4918
/* key is set. */
4924
4919
hval_free = redis_serialize (redis_sock , * z_value_p , & hval , & hval_len TSRMLS_CC );
4925
4920
4926
- old_cmd = cmd ;
4927
- cmd_len = redis_cmd_format (& cmd , "%s"
4928
- "$%d" _NL "%s" _NL
4929
- "$%d" _NL "%s" _NL
4930
- , cmd , cmd_len
4931
- , hkey_len - 1 , hkey , hkey_len - 1
4932
- , hval_len , hval , hval_len );
4933
- efree (old_cmd );
4921
+ // Append our member and value in place
4922
+ redis_cmd_append_sstr (& set_cmds , hkey , hkey_len - 1 );
4923
+ redis_cmd_append_sstr (& set_cmds , hval , hval_len );
4924
+
4934
4925
if (hval_free ) efree (hval );
4935
- if (hkey_free ) efree (hkey );
4936
4926
}
4937
4927
4928
+ // Now construct the entire command
4938
4929
old_cmd = cmd ;
4939
- cmd_len = redis_cmd_format (& cmd , "*%d" _NL "%s"
4940
- , element_count , cmd , cmd_len );
4930
+ cmd_len = redis_cmd_format (& cmd , "*%d" _NL "%s%s" , element_count , cmd , cmd_len , set_cmds .c , set_cmds .len );
4941
4931
efree (old_cmd );
4942
4932
4943
- REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
4944
- IF_ATOMIC () {
4945
- redis_boolean_response (INTERNAL_FUNCTION_PARAM_PASSTHRU , redis_sock , NULL , NULL );
4946
- }
4947
- REDIS_PROCESS_RESPONSE (redis_boolean_response );
4948
- }
4933
+ // Free the HMSET bits
4934
+ efree (set_cmds .c );
4949
4935
4936
+ REDIS_PROCESS_REQUEST (redis_sock , cmd , cmd_len );
4937
+ IF_ATOMIC () {
4938
+ redis_boolean_response (INTERNAL_FUNCTION_PARAM_PASSTHRU , redis_sock , NULL , NULL );
4939
+ }
4940
+ REDIS_PROCESS_RESPONSE (redis_boolean_response );
4941
+ }
4950
4942
4951
4943
4952
4944
PHPAPI int redis_response_enqueued (RedisSock * redis_sock TSRMLS_DC ) {
0 commit comments