From 787b297046b5695c5dbca87060566cf1d93762de Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 10 Mar 2014 13:18:41 +0100 Subject: [PATCH] Cluster: getKeysFromCommand() API cleaned up. This API originated from the "diskstore" experiment, not for Redis Cluster itself, so there were legacy/useless things trying to differentiate between keys that are going to be overwritten and keys that need to be fetched from disk (preloaded). All useless with Cluster, so removed with the result of code simplification. --- src/cluster.c | 3 +-- src/db.c | 27 +++------------------------ src/redis.c | 16 ++++++++-------- src/redis.h | 10 +++------- 4 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 622b90a1..59a71180 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -3897,8 +3897,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg margc = ms->commands[i].argc; margv = ms->commands[i].argv; - keyindex = getKeysFromCommand(mcmd,margv,margc,&numkeys, - REDIS_GETKEYS_ALL); + keyindex = getKeysFromCommand(mcmd,margv,margc,&numkeys); for (j = 0; j < numkeys; j++) { robj *thiskey = margv[keyindex[j]]; int thisslot = keyHashSlot((char*)thiskey->ptr, diff --git a/src/db.c b/src/db.c index d6ef1307..c0641db5 100644 --- a/src/db.c +++ b/src/db.c @@ -949,9 +949,9 @@ int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, in return keys; } -int *getKeysFromCommand(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) { +int *getKeysFromCommand(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) { if (cmd->getkeys_proc) { - return cmd->getkeys_proc(cmd,argv,argc,numkeys,flags); + return cmd->getkeys_proc(cmd,argv,argc,numkeys); } else { return getKeysUsingCommandTable(cmd,argv,argc,numkeys); } @@ -961,30 +961,9 @@ void getKeysFreeResult(int *result) { zfree(result); } -int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) { - if (flags & REDIS_GETKEYS_PRELOAD) { - *numkeys = 0; - return NULL; - } else { - return getKeysUsingCommandTable(cmd,argv,argc,numkeys); - } -} - -int *renameGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) { - if (flags & REDIS_GETKEYS_PRELOAD) { - int *keys = zmalloc(sizeof(int)); - *numkeys = 1; - keys[0] = 1; - return keys; - } else { - return getKeysUsingCommandTable(cmd,argv,argc,numkeys); - } -} - -int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) { +int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) { int i, num, *keys; REDIS_NOTUSED(cmd); - REDIS_NOTUSED(flags); num = atoi(argv[2]->ptr); /* Sanity check. Don't return any key if the command is going to diff --git a/src/redis.c b/src/redis.c index bd875cb7..e018d280 100644 --- a/src/redis.c +++ b/src/redis.c @@ -118,13 +118,13 @@ struct redisCommand *commandTable; */ struct redisCommand redisCommandTable[] = { {"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, - {"set",setCommand,-3,"wm",0,noPreloadGetKeys,1,1,1,0,0}, - {"setnx",setnxCommand,3,"wm",0,noPreloadGetKeys,1,1,1,0,0}, - {"setex",setexCommand,4,"wm",0,noPreloadGetKeys,1,1,1,0,0}, - {"psetex",psetexCommand,4,"wm",0,noPreloadGetKeys,1,1,1,0,0}, + {"set",setCommand,-3,"wm",0,NULL,1,1,1,0,0}, + {"setnx",setnxCommand,3,"wm",0,NULL,1,1,1,0,0}, + {"setex",setexCommand,4,"wm",0,NULL,1,1,1,0,0}, + {"psetex",psetexCommand,4,"wm",0,NULL,1,1,1,0,0}, {"append",appendCommand,3,"wm",0,NULL,1,1,1,0,0}, {"strlen",strlenCommand,2,"r",0,NULL,1,1,1,0,0}, - {"del",delCommand,-2,"w",0,noPreloadGetKeys,1,-1,1,0,0}, + {"del",delCommand,-2,"w",0,NULL,1,-1,1,0,0}, {"exists",existsCommand,2,"r",0,NULL,1,1,1,0,0}, {"setbit",setbitCommand,4,"wm",0,NULL,1,1,1,0,0}, {"getbit",getbitCommand,3,"r",0,NULL,1,1,1,0,0}, @@ -206,8 +206,8 @@ struct redisCommand redisCommandTable[] = { {"randomkey",randomkeyCommand,1,"rR",0,NULL,0,0,0,0,0}, {"select",selectCommand,2,"rl",0,NULL,0,0,0,0,0}, {"move",moveCommand,3,"w",0,NULL,1,1,1,0,0}, - {"rename",renameCommand,3,"w",0,renameGetKeys,1,2,1,0,0}, - {"renamenx",renamenxCommand,3,"w",0,renameGetKeys,1,2,1,0,0}, + {"rename",renameCommand,3,"w",0,NULL,1,2,1,0,0}, + {"renamenx",renamenxCommand,3,"w",0,NULL,1,2,1,0,0}, {"expire",expireCommand,3,"w",0,NULL,1,1,1,0,0}, {"expireat",expireatCommand,3,"w",0,NULL,1,1,1,0,0}, {"pexpire",pexpireCommand,3,"w",0,NULL,1,1,1,0,0}, @@ -247,7 +247,7 @@ struct redisCommand redisCommandTable[] = { {"punsubscribe",punsubscribeCommand,-1,"rpslt",0,NULL,0,0,0,0,0}, {"publish",publishCommand,3,"pltr",0,NULL,0,0,0,0,0}, {"pubsub",pubsubCommand,-2,"pltrR",0,NULL,0,0,0,0,0}, - {"watch",watchCommand,-2,"rs",0,noPreloadGetKeys,1,-1,1,0,0}, + {"watch",watchCommand,-2,"rs",0,NULL,1,-1,1,0,0}, {"unwatch",unwatchCommand,1,"rs",0,NULL,0,0,0,0,0}, {"cluster",clusterCommand,-2,"ar",0,NULL,0,0,0,0,0}, {"restore",restoreCommand,-4,"awm",0,NULL,1,1,1,0,0}, diff --git a/src/redis.h b/src/redis.h index 0348421f..6ea0c22c 100644 --- a/src/redis.h +++ b/src/redis.h @@ -826,7 +826,7 @@ typedef struct pubsubPattern { } pubsubPattern; typedef void redisCommandProc(redisClient *c); -typedef int *redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, int *numkeys, int flags); +typedef int *redisGetKeysProc(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); struct redisCommand { char *name; redisCommandProc *proc; @@ -1237,13 +1237,9 @@ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor); int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor); /* API to get key arguments from commands */ -#define REDIS_GETKEYS_ALL 0 -#define REDIS_GETKEYS_PRELOAD 1 -int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys, int flags); +int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys); void getKeysFreeResult(int *result); -int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags); -int *renameGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags); -int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags); +int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys); /* Cluster */ void clusterInit(void);