Skip to content

Commit 9950a11

Browse files
committed
redis_array_impl.c refactoring
1 parent 0b2b809 commit 9950a11

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

redis_array_impl.c

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,11 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
425425
char *start, *end;
426426
*out_len = key_len;
427427

428-
if(ra->z_fun)
428+
if(ra->z_fun) {
429429
return ra_call_extractor(ra, key, key_len, out_len TSRMLS_CC);
430-
431-
/* look for '{' */
432-
start = strchr(key, '{');
433-
if(!start) return estrndup(key, key_len);
434-
435-
/* look for '}' */
436-
end = strchr(start + 1, '}');
437-
if(!end) return estrndup(key, key_len);
438-
430+
} else if ((start = strchr(key, '{')) == NULL || (end = strchr(start + 1, '}')) == NULL) {
431+
return estrndup(key, key_len);
432+
}
439433
/* found substring */
440434
*out_len = end - start - 1;
441435
return estrndup(start + 1, *out_len);
@@ -768,17 +762,6 @@ ra_rehash_scan(zval *z_redis, char ***keys, int **key_lens, const char *cmd, con
768762
return count;
769763
}
770764

771-
static long
772-
ra_rehash_scan_index(zval *z_redis, char ***keys, int **key_lens TSRMLS_DC) {
773-
return ra_rehash_scan(z_redis, keys, key_lens, "SMEMBERS", PHPREDIS_INDEX_NAME TSRMLS_CC);
774-
}
775-
776-
/* list keys using KEYS command */
777-
static long
778-
ra_rehash_scan_keys(zval *z_redis, char ***keys, int **key_lens TSRMLS_DC) {
779-
return ra_rehash_scan(z_redis, keys, key_lens, "KEYS", "*" TSRMLS_CC);
780-
}
781-
782765
/* run TYPE to find the type */
783766
static zend_bool
784767
ra_get_key_type(zval *z_redis, const char *key, int key_len, zval *z_from, long *res TSRMLS_DC) {
@@ -1254,9 +1237,9 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
12541237

12551238
/* list all keys */
12561239
if(b_index) {
1257-
count = ra_rehash_scan_index(z_redis, &keys, &key_lens TSRMLS_CC);
1240+
count = ra_rehash_scan(z_redis, &keys, &key_lens, "SMEMBERS", PHPREDIS_INDEX_NAME TSRMLS_CC);
12581241
} else {
1259-
count = ra_rehash_scan_keys(z_redis, &keys, &key_lens TSRMLS_CC);
1242+
count = ra_rehash_scan(z_redis, &keys, &key_lens, "KEYS", "*" TSRMLS_CC);
12601243
}
12611244

12621245
/* callback */
@@ -1274,12 +1257,11 @@ ra_rehash_server(RedisArray *ra, zval *z_redis, const char *hostname, zend_bool
12741257
/* php_printf("move [%s] from [%s] to [%s]\n", keys[i], hostname, ra->hosts[target_pos]); */
12751258
ra_move_key(keys[i], key_lens[i], z_redis, z_target TSRMLS_CC);
12761259
}
1277-
}
12781260

1279-
/* cleanup */
1280-
for(i = 0; i < count; ++i) {
1261+
/* cleanup */
12811262
efree(keys[i]);
12821263
}
1264+
12831265
efree(keys);
12841266
efree(key_lens);
12851267
}

redis_commands.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3309,4 +3309,4 @@ void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS,
33093309
}
33103310
}
33113311

3312-
/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */
3312+
/* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */

redis_session.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
+----------------------------------------------------------------------+
2121
*/
2222

23-
#include "common.h"
24-
2523
#ifdef HAVE_CONFIG_H
2624
#include "config.h"
2725
#endif

0 commit comments

Comments
 (0)