mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Changed DEL to use index when available.
This commit is contained in:
+21
-2
@@ -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);
|
||||
|
||||
|
||||
+30
-2
@@ -386,6 +386,36 @@ ra_index_multi(zval *z_redis TSRMLS_DC) {
|
||||
//zval_dtor(&z_ret);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user