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:
-rw-r--r--redis_array.c23
-rw-r--r--redis_array_impl.c32
-rw-r--r--redis_array_impl.h1
3 files changed, 52 insertions, 4 deletions
diff --git a/redis_array.c b/redis_array.c
index 34e2bb11..9ce9d558 100644
--- a/redis_array.c
+++ b/redis_array.c
@@ -892,6 +892,7 @@ PHP_METHOD(RedisArray, del)
/* calls */
for(n = 0; n < ra->count; ++n) { /* for each node */
+ int found = 0;
redis_inst = ra->redis[n];
/* copy args */
@@ -906,14 +907,32 @@ PHP_METHOD(RedisArray, del)
INIT_PZVAL(z_tmp);
add_next_index_zval(z_argarray, z_tmp);
+ found++;
+ }
+
+ if(!found) { // don't run empty DELs
+ zval_dtor(z_argarray);
+ efree(z_argarray);
+ continue;
+ }
+
+ if(ra->index) { /* add MULTI */
+ ra_index_multi(redis_inst TSRMLS_CC);
}
/* call */
MAKE_STD_ZVAL(z_ret);
- call_user_function(&redis_ce->function_table, &ra->redis[n],
+ call_user_function(&redis_ce->function_table, &redis_inst,
&z_fun, z_ret, 1, &z_argarray TSRMLS_CC);
- total += Z_LVAL_P(z_ret); /* increment total */
+ if(ra->index) {
+ ra_index_del(z_argarray, redis_inst TSRMLS_CC); /* use SREM to remove keys from node index */
+ ra_index_exec(redis_inst, z_tmp, 0 TSRMLS_CC); /* run EXEC */
+ total += Z_LVAL_P(z_tmp); /* increment total from multi/exec block */
+ } else {
+ total += Z_LVAL_P(z_ret); /* increment total from single command */
+ }
+
zval_dtor(z_ret);
efree(z_ret);
diff --git a/redis_array_impl.c b/redis_array_impl.c
index 902abc06..bf0ea0bb 100644
--- a/redis_array_impl.c
+++ b/redis_array_impl.c
@@ -387,6 +387,36 @@ ra_index_multi(zval *z_redis TSRMLS_DC) {
}
void
+ra_index_del(zval *z_keys, zval *z_redis TSRMLS_DC) {
+
+ int i, argc;
+ zval z_fun_srem, z_ret, **z_args;
+
+ /* alloc */
+ argc = 1 + zend_hash_num_elements(Z_ARRVAL_P(z_keys));
+ z_args = emalloc(argc * sizeof(zval*));
+
+ /* prepare first parameters */
+ ZVAL_STRINGL(&z_fun_srem, "SREM", 4, 0);
+ MAKE_STD_ZVAL(z_args[0]);
+ ZVAL_STRING(z_args[0], PHPREDIS_INDEX_NAME, 0);
+
+ /* prepare keys */
+ for(i = 0; i < argc - 1; ++i) {
+ zval **zpp;
+ zend_hash_quick_find(Z_ARRVAL_P(z_keys), NULL, 0, i, (void**)&zpp);
+ z_args[i+1] = *zpp;
+ }
+
+ /* run SREM */
+ call_user_function(&redis_ce->function_table, &z_redis, &z_fun_srem, &z_ret, argc, z_args TSRMLS_CC);
+
+ /* don't dtor z_ret, since we're returning z_redis */
+ efree(z_args[0]); /* free index name zval */
+ efree(z_args); /* free container */
+}
+
+void
ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
int i;
@@ -400,12 +430,10 @@ ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC) {
ZVAL_STRING(z_args[0], PHPREDIS_INDEX_NAME, 0);
ZVAL_STRINGL(z_args[1], key, key_len, 1);
-
/* run SADD */
call_user_function(&redis_ce->function_table, &z_redis, &z_fun_sadd, &z_ret, 2, z_args TSRMLS_CC);
/* don't dtor z_ret, since we're returning z_redis */
-
efree(z_args[0]);
efree(z_args[1]);
}
diff --git a/redis_array_impl.h b/redis_array_impl.h
index a9be177c..9044c2a5 100644
--- a/redis_array_impl.h
+++ b/redis_array_impl.h
@@ -17,6 +17,7 @@ char * ra_find_key(RedisArray *ra, zval *z_args, const char *cmd, int *key_len);
void ra_index_multi(zval *z_redis TSRMLS_DC);
void ra_index_key(const char *key, int key_len, zval *z_redis TSRMLS_DC);
+void ra_index_del(zval *z_keys, zval *z_redis TSRMLS_DC);
void ra_index_exec(zval *z_redis, zval *return_value, int keep_all TSRMLS_DC);
zend_bool ra_is_write_cmd(RedisArray *ra, const char *cmd, int cmd_len);