Skip to content

Commit 8978b3a

Browse files
Tabs are evil
1 parent f81694e commit 8978b3a

File tree

1 file changed

+72
-68
lines changed

1 file changed

+72
-68
lines changed

redis_array.c

Lines changed: 72 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,11 +1005,11 @@ PHP_METHOD(RedisArray, mget)
10051005
/* MSET will distribute the call to several nodes and regroup the values. */
10061006
PHP_METHOD(RedisArray, mset)
10071007
{
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;
10131013
char *key, **keys, kbuf[40];
10141014
int key_len, *key_lens;
10151015
zend_string *zkey;
@@ -1019,106 +1019,110 @@ PHP_METHOD(RedisArray, mset)
10191019
RETURN_FALSE;
10201020
}
10211021

1022-
/* Multi/exec support */
1022+
/* Multi/exec support */
10231023
HANDLE_MULTI_EXEC(ra, "MSET");
10241024

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+
}
10291030

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));
10371038

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));
10401041

1041-
/* associate each key to a redis node */
1042-
i = 0;
1042+
/* associate each key to a redis node */
10431043
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 */
10451045
if (zkey) {
10461046
key_len = zkey->len;
10471047
key = zkey->val;
10481048
} else {
1049-
key_len = snprintf(kbuf, sizeof(kbuf), "%lu", idx);
1049+
key_len = snprintf(kbuf, sizeof(kbuf), "%lu", idx);
10501050
key = kbuf;
10511051
}
10521052

10531053
if (ra_find_node(ra, key, (int)key_len, &pos[i] TSRMLS_CC) == NULL) {
10541054
// TODO: handle
10551055
}
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;
10601061
i++;
1061-
} ZEND_HASH_FOREACH_END();
1062+
} ZEND_HASH_FOREACH_END();
10621063

10631064

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;
10681069

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;
10701076

1071-
/* copy args */
1072-
array_init(&z_argarray);
1073-
for(i = 0; i < argc; ++i) {
1074-
if(pos[i] != n) continue;
10751077
zval zv, *z_tmp = &zv;
10761078
#if (PHP_MAJOR_VERSION < 7)
10771079
MAKE_STD_ZVAL(z_tmp);
10781080
#endif
10791081
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+
}
10831085

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+
}
10891090

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+
}
10931094

10941095
zval z_fun;
1096+
10951097
/* prepare call */
10961098
ZVAL_STRINGL(&z_fun, "MSET", 4);
1097-
/* call */
1099+
1100+
/* call */
10981101
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);
11011104

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+
}
11081109

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+
}
11131112

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);
11201124

1121-
RETURN_TRUE;
1125+
RETURN_TRUE;
11221126
}
11231127

11241128
/* DEL will distribute the call to several nodes and regroup the values. */

0 commit comments

Comments
 (0)