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:
authormichael-grunder <michael.grunder@gmail.com>2014-06-03 04:18:36 +0400
committermichael-grunder <michael.grunder@gmail.com>2015-05-06 00:32:55 +0300
commitd7776a97276a9a8962e6d245c828abfe61993fbd (patch)
treec27b31679900642b7f4bb2a93f5436693d2ddc5e /cluster_library.c
parentd6916a43e02580431c7d4ee8e78198761d7a7cab (diff)
MULTI BULK processing for things like HGETALL and ZRANGE
Diffstat (limited to 'cluster_library.c')
-rw-r--r--cluster_library.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/cluster_library.c b/cluster_library.c
index 933b199d..3e36b8c1 100644
--- a/cluster_library.c
+++ b/cluster_library.c
@@ -1187,7 +1187,7 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
long long count TSRMLS_DC)
{
char *line, *key;
- int line_len;
+ int line_len, key_len;
long long idx=0;
zval *z;
@@ -1202,15 +1202,17 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
if(!line) return -1;
- if(idx % 2 == 0) {
- // Save our key
+ if(idx++ % 2 == 0) {
+ // Save our key and length
key = line;
+ key_len = line_len;
} else {
// Attempt unserialization, add value
if(redis_unserialize(redis_sock, line, line_len, &z TSRMLS_CC)==1) {
add_assoc_zval(z_result, key, z);
} else {
- add_assoc_stringl(z_result, key, line, line_len, 0);
+ add_assoc_stringl_ex(z_result, key, 1+key_len, line,
+ line_len, 0);
}
}
}
@@ -1218,4 +1220,34 @@ int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
return SUCCESS;
}
+/* MULTI BULK loop processor where we expect key,score key, score */
+int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
+ long long count TSRMLS_DC)
+{
+ char *line, *key;
+ int line_len, key_len;
+ long long idx=0;
+ double score;
+
+ // Our context will need to be divisible by 2
+ if(count %2 != 0) {
+ return -1;
+ }
+
+ // While we have elements
+ while(count--) {
+ line = redis_sock_read(redis_sock, &line_len TSRMLS_CC);
+ if(!line) return -1;
+
+ if(idx++ % 2 == 0) {
+ key = line;
+ key_len = line_len;
+ } else {
+ add_assoc_double_ex(z_result, key, 1+key_len, atof(line));
+ }
+ }
+
+ return SUCCESS;
+}
+
/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */