mirror of
https://github.com/phpredis/phpredis.git
synced 2026-06-19 07:35:31 +00:00
Rework CLUSTER_PROCESS_KW_CMD to be a small wrapper macro + function
This commit is similar to the last one reworking processing keyword commands to work to use a function instead of a big multiline macro.
This commit is contained in:
committed by
Michael Grunder
parent
1db3908914
commit
b90e27f285
@@ -75,6 +75,40 @@ cluster_process_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
|
||||
resp_cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx);
|
||||
}
|
||||
|
||||
void
|
||||
cluster_process_kw_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
|
||||
const char *kw, redis_kw_cmd_cb cmd_cb, cluster_cb resp_cb,
|
||||
int readonly)
|
||||
{
|
||||
void *ctx = NULL;
|
||||
int cmd_len;
|
||||
short slot;
|
||||
char *cmd;
|
||||
|
||||
c->readonly = readonly && CLUSTER_IS_ATOMIC(c);
|
||||
|
||||
/* TODO: Update kw commands to take a const char * */
|
||||
if (cmd_cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, (char*)kw, &cmd, &cmd_len,
|
||||
&slot, &ctx) == FAILURE)
|
||||
{
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
if (cluster_send_command(c, slot, cmd, cmd_len) < 0 || c->err != NULL) {
|
||||
efree(cmd);
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
efree(cmd);
|
||||
|
||||
if (c->flags->mode == MULTI) {
|
||||
CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_cb, ctx);
|
||||
RETURN_ZVAL(getThis(), 1, 0);
|
||||
}
|
||||
|
||||
resp_cb(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx);
|
||||
}
|
||||
|
||||
PHP_MINIT_FUNCTION(redis_cluster)
|
||||
{
|
||||
redis_cluster_ce = register_class_RedisCluster();
|
||||
|
||||
+6
-19
@@ -60,25 +60,12 @@ void cluster_process_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
|
||||
cluster_process_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, GET_CONTEXT(), \
|
||||
redis_##cmdname##_cmd, resp_func, readcmd)
|
||||
|
||||
/* More generic processing, where only the keyword differs */
|
||||
#define CLUSTER_PROCESS_KW_CMD(kw, cmdfunc, resp_func, readcmd) \
|
||||
redisCluster *c = GET_CONTEXT(); \
|
||||
c->readonly = CLUSTER_IS_ATOMIC(c) && readcmd; \
|
||||
char *cmd; int cmd_len; short slot; void *ctx=NULL; \
|
||||
if(cmdfunc(INTERNAL_FUNCTION_PARAM_PASSTHRU, c->flags, kw, &cmd, &cmd_len,\
|
||||
&slot,&ctx)==FAILURE) { \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
if(cluster_send_command(c,slot,cmd,cmd_len)<0 || c->err!=NULL) { \
|
||||
efree(cmd); \
|
||||
RETURN_FALSE; \
|
||||
} \
|
||||
efree(cmd); \
|
||||
if(c->flags->mode == MULTI) { \
|
||||
CLUSTER_ENQUEUE_RESPONSE(c, slot, resp_func, ctx); \
|
||||
RETURN_ZVAL(getThis(), 1, 0); \
|
||||
} \
|
||||
resp_func(INTERNAL_FUNCTION_PARAM_PASSTHRU, c, ctx);
|
||||
void cluster_process_kw_cmd(INTERNAL_FUNCTION_PARAMETERS, redisCluster *c,
|
||||
const char *kw, redis_kw_cmd_cb cmd_cb, cluster_cb resp_cb, int readonly);
|
||||
|
||||
#define CLUSTER_PROCESS_KW_CMD(kw, cmd_cb, resp_cb, readonly) \
|
||||
cluster_process_kw_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU, GET_CONTEXT(), \
|
||||
kw, cmd_cb, resp_cb, readonly)
|
||||
|
||||
extern zend_class_entry *redis_cluster_ce;
|
||||
extern zend_class_entry *redis_cluster_exception_ce;
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ typedef int (*redis_cmd_cb)(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char **cmd, int *cmd_len, short *slot, void **ctx);
|
||||
|
||||
typedef int (*redis_kw_cmd_cb)(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
|
||||
char *kw, char **cmd, int *cmd_len, short *slot,
|
||||
void **ctx);
|
||||
char *kw, char **cmd, int *cmd_len, short *slot,
|
||||
void **ctx);
|
||||
|
||||
/* Redis command generics. Many commands share common prototypes meaning that
|
||||
* we can write one function to handle all of them. For example, there are
|
||||
|
||||
Reference in New Issue
Block a user