@@ -1005,11 +1005,11 @@ PHP_METHOD(RedisArray, mget)
1005
1005
/* MSET will distribute the call to several nodes and regroup the values. */
1006
1006
PHP_METHOD (RedisArray , mset )
1007
1007
{
1008
- zval * object , * z_keys , z_argarray , * data , z_ret , * * argv ;
1009
- int i , n ;
1010
- RedisArray * ra ;
1011
- int * pos , argc , * argc_each ;
1012
- HashTable * h_keys ;
1008
+ zval * object , * z_keys , z_argarray , * data , z_ret , * * argv ;
1009
+ int i = 0 , n ;
1010
+ RedisArray * ra ;
1011
+ int * pos , argc , * argc_each ;
1012
+ HashTable * h_keys ;
1013
1013
char * key , * * keys , kbuf [40 ];
1014
1014
int key_len , * key_lens ;
1015
1015
zend_string * zkey ;
@@ -1019,106 +1019,110 @@ PHP_METHOD(RedisArray, mset)
1019
1019
RETURN_FALSE ;
1020
1020
}
1021
1021
1022
- /* Multi/exec support */
1022
+ /* Multi/exec support */
1023
1023
HANDLE_MULTI_EXEC (ra , "MSET" );
1024
1024
1025
- if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
1026
- & object , redis_array_ce , & z_keys ) == FAILURE ) {
1027
- RETURN_FALSE ;
1028
- }
1025
+ if (zend_parse_method_parameters (ZEND_NUM_ARGS () TSRMLS_CC , getThis (), "Oa" ,
1026
+ & object , redis_array_ce , & z_keys ) == FAILURE )
1027
+ {
1028
+ RETURN_FALSE ;
1029
+ }
1029
1030
1030
- /* init data structures */
1031
- h_keys = Z_ARRVAL_P (z_keys );
1032
- argc = zend_hash_num_elements (h_keys );
1033
- argv = emalloc (argc * sizeof (zval * ));
1034
- pos = emalloc (argc * sizeof (int ));
1035
- keys = emalloc (argc * sizeof (char * ));
1036
- key_lens = emalloc (argc * sizeof (int ));
1031
+ /* init data structures */
1032
+ h_keys = Z_ARRVAL_P (z_keys );
1033
+ argc = zend_hash_num_elements (h_keys );
1034
+ argv = emalloc (argc * sizeof (zval * ));
1035
+ pos = emalloc (argc * sizeof (int ));
1036
+ keys = emalloc (argc * sizeof (char * ));
1037
+ key_lens = emalloc (argc * sizeof (int ));
1037
1038
1038
- argc_each = emalloc (ra -> count * sizeof (int ));
1039
- memset (argc_each , 0 , ra -> count * sizeof (int ));
1039
+ argc_each = emalloc (ra -> count * sizeof (int ));
1040
+ memset (argc_each , 0 , ra -> count * sizeof (int ));
1040
1041
1041
- /* associate each key to a redis node */
1042
- i = 0 ;
1042
+ /* associate each key to a redis node */
1043
1043
ZEND_HASH_FOREACH_KEY_VAL (h_keys , idx , zkey , data ) {
1044
- /* If the key isn't a string, make a string representation of it */
1044
+ /* If the key isn't a string, make a string representation of it */
1045
1045
if (zkey ) {
1046
1046
key_len = zkey -> len ;
1047
1047
key = zkey -> val ;
1048
1048
} else {
1049
- key_len = snprintf (kbuf , sizeof (kbuf ), "%lu" , idx );
1049
+ key_len = snprintf (kbuf , sizeof (kbuf ), "%lu" , idx );
1050
1050
key = kbuf ;
1051
1051
}
1052
1052
1053
1053
if (ra_find_node (ra , key , (int )key_len , & pos [i ] TSRMLS_CC ) == NULL ) {
1054
1054
// TODO: handle
1055
1055
}
1056
- argc_each [pos [i ]]++ ; /* count number of keys per node */
1057
- keys [i ] = estrndup (key , key_len );
1058
- key_lens [i ] = (int )key_len ;
1059
- argv [i ] = data ;
1056
+
1057
+ argc_each [pos [i ]]++ ; /* count number of keys per node */
1058
+ keys [i ] = estrndup (key , key_len );
1059
+ key_lens [i ] = (int )key_len ;
1060
+ argv [i ] = data ;
1060
1061
i ++ ;
1061
- } ZEND_HASH_FOREACH_END ();
1062
+ } ZEND_HASH_FOREACH_END ();
1062
1063
1063
1064
1064
- /* calls */
1065
- for (n = 0 ; n < ra -> count ; ++ n ) { /* for each node */
1066
- /* We don't even need to make a call to this node if no keys go there */
1067
- if (!argc_each [n ]) continue ;
1065
+ /* calls */
1066
+ for (n = 0 ; n < ra -> count ; ++ n ) { /* for each node */
1067
+ /* We don't even need to make a call to this node if no keys go there */
1068
+ if (!argc_each [n ]) continue ;
1068
1069
1069
- int found = 0 ;
1070
+ int found = 0 ;
1071
+
1072
+ /* copy args */
1073
+ array_init (& z_argarray );
1074
+ for (i = 0 ; i < argc ; ++ i ) {
1075
+ if (pos [i ] != n ) continue ;
1070
1076
1071
- /* copy args */
1072
- array_init (& z_argarray );
1073
- for (i = 0 ; i < argc ; ++ i ) {
1074
- if (pos [i ] != n ) continue ;
1075
1077
zval zv , * z_tmp = & zv ;
1076
1078
#if (PHP_MAJOR_VERSION < 7 )
1077
1079
MAKE_STD_ZVAL (z_tmp );
1078
1080
#endif
1079
1081
ZVAL_ZVAL (z_tmp , argv [i ], 1 , 0 );
1080
- add_assoc_zval_ex (& z_argarray , keys [i ], key_lens [i ], z_tmp );
1081
- found ++ ;
1082
- }
1082
+ add_assoc_zval_ex (& z_argarray , keys [i ], key_lens [i ], z_tmp );
1083
+ found ++ ;
1084
+ }
1083
1085
1084
- if (!found )
1085
- {
1086
- zval_dtor (& z_argarray );
1087
- continue ; /* don't run empty MSETs */
1088
- }
1086
+ if (!found ) {
1087
+ zval_dtor (& z_argarray );
1088
+ continue ; /* don't run empty MSETs */
1089
+ }
1089
1090
1090
- if (ra -> index ) { /* add MULTI */
1091
- ra_index_multi (& ra -> redis [n ], MULTI TSRMLS_CC );
1092
- }
1091
+ if (ra -> index ) { /* add MULTI */
1092
+ ra_index_multi (& ra -> redis [n ], MULTI TSRMLS_CC );
1093
+ }
1093
1094
1094
1095
zval z_fun ;
1096
+
1095
1097
/* prepare call */
1096
1098
ZVAL_STRINGL (& z_fun , "MSET" , 4 );
1097
- /* call */
1099
+
1100
+ /* call */
1098
1101
call_user_function (& redis_ce -> function_table , & ra -> redis [n ], & z_fun , & z_ret , 1 , & z_argarray );
1099
- zval_dtor (& z_fun );
1100
- zval_dtor (& z_ret );
1102
+ zval_dtor (& z_fun );
1103
+ zval_dtor (& z_ret );
1101
1104
1102
- if (ra -> index ) {
1103
- ra_index_keys (& z_argarray , & ra -> redis [n ] TSRMLS_CC ); /* use SADD to add keys to node index */
1104
- ra_index_exec (& ra -> redis [n ], NULL , 0 TSRMLS_CC ); /* run EXEC */
1105
- }
1106
- zval_dtor (& z_argarray );
1107
- }
1105
+ if (ra -> index ) {
1106
+ ra_index_keys (& z_argarray , & ra -> redis [n ] TSRMLS_CC ); /* use SADD to add keys to node index */
1107
+ ra_index_exec (& ra -> redis [n ], NULL , 0 TSRMLS_CC ); /* run EXEC */
1108
+ }
1108
1109
1109
- /* Free any keys that we needed to allocate memory for, because they weren't strings */
1110
- for (i = 0 ; i < argc ; i ++ ) {
1111
- efree (keys [i ]);
1112
- }
1110
+ zval_dtor (& z_argarray );
1111
+ }
1113
1112
1114
- /* cleanup */
1115
- efree (keys );
1116
- efree (key_lens );
1117
- efree (argv );
1118
- efree (pos );
1119
- efree (argc_each );
1113
+ /* Free any keys that we needed to allocate memory for, because they weren't strings */
1114
+ for (i = 0 ; i < argc ; i ++ ) {
1115
+ efree (keys [i ]);
1116
+ }
1117
+
1118
+ /* cleanup */
1119
+ efree (keys );
1120
+ efree (key_lens );
1121
+ efree (argv );
1122
+ efree (pos );
1123
+ efree (argc_each );
1120
1124
1121
- RETURN_TRUE ;
1125
+ RETURN_TRUE ;
1122
1126
}
1123
1127
1124
1128
/* DEL will distribute the call to several nodes and regroup the values. */
0 commit comments