mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 22:31:03 +00:00
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.
This commit is contained in:
parent
55b88e0044
commit
787b297046
@ -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,
|
||||||
|
27
src/db.c
27
src/db.c
@ -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) {
|
|||||||
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
|
||||||
|
16
src/redis.c
16
src/redis.c
@ -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[] = {
|
|||||||
{"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[] = {
|
|||||||
{"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},
|
||||||
|
10
src/redis.h
10
src/redis.h
@ -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);
|
|||||||
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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user