Commit 787b2970 authored by antirez's avatar antirez
Browse files

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.
parent 55b88e00
...@@ -3897,8 +3897,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg ...@@ -3897,8 +3897,7 @@ clusterNode *getNodeByQuery(redisClient *c, struct redisCommand *cmd, robj **arg
margc = ms->commands[i].argc; margc = ms->commands[i].argc;
margv = ms->commands[i].argv; margv = ms->commands[i].argv;
keyindex = getKeysFromCommand(mcmd,margv,margc,&numkeys, keyindex = getKeysFromCommand(mcmd,margv,margc,&numkeys);
REDIS_GETKEYS_ALL);
for (j = 0; j < numkeys; j++) { for (j = 0; j < numkeys; j++) {
robj *thiskey = margv[keyindex[j]]; robj *thiskey = margv[keyindex[j]];
int thisslot = keyHashSlot((char*)thiskey->ptr, int thisslot = keyHashSlot((char*)thiskey->ptr,
......
...@@ -949,9 +949,9 @@ int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, in ...@@ -949,9 +949,9 @@ int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, in
return keys; 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) { if (cmd->getkeys_proc) {
return cmd->getkeys_proc(cmd,argv,argc,numkeys,flags); return cmd->getkeys_proc(cmd,argv,argc,numkeys);
} else { } else {
return getKeysUsingCommandTable(cmd,argv,argc,numkeys); return getKeysUsingCommandTable(cmd,argv,argc,numkeys);
} }
...@@ -961,30 +961,9 @@ void getKeysFreeResult(int *result) { ...@@ -961,30 +961,9 @@ void getKeysFreeResult(int *result) {
zfree(result); zfree(result);
} }
int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags) { int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) {
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 i, num, *keys; int i, num, *keys;
REDIS_NOTUSED(cmd); REDIS_NOTUSED(cmd);
REDIS_NOTUSED(flags);
num = atoi(argv[2]->ptr); num = atoi(argv[2]->ptr);
/* Sanity check. Don't return any key if the command is going to /* Sanity check. Don't return any key if the command is going to
......
...@@ -118,13 +118,13 @@ struct redisCommand *commandTable; ...@@ -118,13 +118,13 @@ struct redisCommand *commandTable;
*/ */
struct redisCommand redisCommandTable[] = { struct redisCommand redisCommandTable[] = {
{"get",getCommand,2,"r",0,NULL,1,1,1,0,0}, {"get",getCommand,2,"r",0,NULL,1,1,1,0,0},
{"set",setCommand,-3,"wm",0,noPreloadGetKeys,1,1,1,0,0}, {"set",setCommand,-3,"wm",0,NULL,1,1,1,0,0},
{"setnx",setnxCommand,3,"wm",0,noPreloadGetKeys,1,1,1,0,0}, {"setnx",setnxCommand,3,"wm",0,NULL,1,1,1,0,0},
{"setex",setexCommand,4,"wm",0,noPreloadGetKeys,1,1,1,0,0}, {"setex",setexCommand,4,"wm",0,NULL,1,1,1,0,0},
{"psetex",psetexCommand,4,"wm",0,noPreloadGetKeys,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}, {"append",appendCommand,3,"wm",0,NULL,1,1,1,0,0},
{"strlen",strlenCommand,2,"r",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}, {"exists",existsCommand,2,"r",0,NULL,1,1,1,0,0},
{"setbit",setbitCommand,4,"wm",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}, {"getbit",getbitCommand,3,"r",0,NULL,1,1,1,0,0},
...@@ -206,8 +206,8 @@ struct redisCommand redisCommandTable[] = { ...@@ -206,8 +206,8 @@ struct redisCommand redisCommandTable[] = {
{"randomkey",randomkeyCommand,1,"rR",0,NULL,0,0,0,0,0}, {"randomkey",randomkeyCommand,1,"rR",0,NULL,0,0,0,0,0},
{"select",selectCommand,2,"rl",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}, {"move",moveCommand,3,"w",0,NULL,1,1,1,0,0},
{"rename",renameCommand,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,renameGetKeys,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}, {"expire",expireCommand,3,"w",0,NULL,1,1,1,0,0},
{"expireat",expireatCommand,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}, {"pexpire",pexpireCommand,3,"w",0,NULL,1,1,1,0,0},
...@@ -247,7 +247,7 @@ struct redisCommand redisCommandTable[] = { ...@@ -247,7 +247,7 @@ struct redisCommand redisCommandTable[] = {
{"punsubscribe",punsubscribeCommand,-1,"rpslt",0,NULL,0,0,0,0,0}, {"punsubscribe",punsubscribeCommand,-1,"rpslt",0,NULL,0,0,0,0,0},
{"publish",publishCommand,3,"pltr",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}, {"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}, {"unwatch",unwatchCommand,1,"rs",0,NULL,0,0,0,0,0},
{"cluster",clusterCommand,-2,"ar",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}, {"restore",restoreCommand,-4,"awm",0,NULL,1,1,1,0,0},
......
...@@ -826,7 +826,7 @@ typedef struct pubsubPattern { ...@@ -826,7 +826,7 @@ typedef struct pubsubPattern {
} pubsubPattern; } pubsubPattern;
typedef void redisCommandProc(redisClient *c); 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 { struct redisCommand {
char *name; char *name;
redisCommandProc *proc; redisCommandProc *proc;
...@@ -1237,13 +1237,9 @@ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor); ...@@ -1237,13 +1237,9 @@ void scanGenericCommand(redisClient *c, robj *o, unsigned long cursor);
int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor); int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor);
/* API to get key arguments from commands */ /* API to get key arguments from commands */
#define REDIS_GETKEYS_ALL 0 int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
#define REDIS_GETKEYS_PRELOAD 1
int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys, int flags);
void getKeysFreeResult(int *result); void getKeysFreeResult(int *result);
int *noPreloadGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys, int flags); int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys);
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);
/* Cluster */ /* Cluster */
void clusterInit(void); void clusterInit(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment