Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Favre-Felix <n.favrefelix@gmail.com>2010-09-17 12:06:42 +0400
committerNicolas Favre-Felix <n.favrefelix@gmail.com>2010-09-17 12:06:42 +0400
commite4adc956ad3aae8f67d49bb44f911f1cea567f9c (patch)
treebda7bb7588940db5793b4f0838fb67b9d6ff2895 /redis.c
parent02882154a98eb1db91ad052623681551149afd1e (diff)
Added array of patterns to 'get' option in SORT().
Diffstat (limited to 'redis.c')
-rwxr-xr-xredis.c56
1 files changed, 45 insertions, 11 deletions
diff --git a/redis.c b/redis.c
index 841b23c2..3fc4c49f 100755
--- a/redis.c
+++ b/redis.c
@@ -2060,18 +2060,51 @@ PHP_METHOD(Redis, sort) {
if ((zend_hash_find(Z_ARRVAL_P(z_array), "get", sizeof("get"), (void **) &z_cur) == SUCCESS
|| zend_hash_find(Z_ARRVAL_P(z_array), "GET", sizeof("GET"), (void **) &z_cur) == SUCCESS)
- && Z_TYPE_PP(z_cur) == IS_STRING) {
+ && (Z_TYPE_PP(z_cur) == IS_STRING || Z_TYPE_PP(z_cur) == IS_ARRAY)) {
- old_cmd = cmd;
- cmd_len = redis_cmd_format(&cmd, "%s"
- "$3" _NL
- "GET" _NL
- "$%d" _NL
- "%s" _NL
- , cmd, cmd_len
- , Z_STRLEN_PP(z_cur), Z_STRVAL_PP(z_cur), Z_STRLEN_PP(z_cur));
- elements += 2;
- efree(old_cmd);
+ if(Z_TYPE_PP(z_cur) == IS_STRING) {
+ old_cmd = cmd;
+ cmd_len = redis_cmd_format(&cmd, "%s"
+ "$3" _NL
+ "GET" _NL
+ "$%d" _NL
+ "%s" _NL
+ , cmd, cmd_len
+ , Z_STRLEN_PP(z_cur), Z_STRVAL_PP(z_cur), Z_STRLEN_PP(z_cur));
+ elements += 2;
+ efree(old_cmd);
+ } else if(Z_TYPE_PP(z_cur) == IS_ARRAY) { // loop over the strings in that array and add them as patterns
+
+ HashTable *keytable = Z_ARRVAL_PP(z_cur);
+ for(zend_hash_internal_pointer_reset(keytable);
+ zend_hash_has_more_elements(keytable) == SUCCESS;
+ zend_hash_move_forward(keytable)) {
+
+ char *key, *val;
+ int key_len, val_len;
+ unsigned long idx;
+ int type;
+ zval **z_value_pp;
+
+ type = zend_hash_get_current_key_ex(keytable, &key, &key_len, &idx, 0, NULL);
+ if(zend_hash_get_current_data(keytable, (void**)&z_value_pp) == FAILURE) {
+ continue; /* this should never happen, according to the PHP people. */
+ }
+
+ if(Z_TYPE_PP(z_value_pp) == IS_STRING) {
+ old_cmd = cmd;
+ cmd_len = redis_cmd_format(&cmd, "%s"
+ "$3" _NL
+ "GET" _NL
+ "$%d" _NL
+ "%s" _NL
+ , cmd, cmd_len
+ , Z_STRLEN_PP(z_value_pp), Z_STRVAL_PP(z_value_pp), Z_STRLEN_PP(z_value_pp));
+ elements += 2;
+ efree(old_cmd);
+ }
+ }
+ }
}
if ((zend_hash_find(Z_ARRVAL_P(z_array), "alpha", sizeof("alpha"), (void **) &z_cur) == SUCCESS
@@ -2122,6 +2155,7 @@ PHP_METHOD(Redis, sort) {
}
/* complete with prefix */
+
old_cmd = cmd;
cmd_len = redis_cmd_format(&cmd, "*%d" _NL "%s",
elements, cmd, cmd_len);