Permalink
Browse files

Cluster: evalGetKey() added for EVAL/EVALSHA.

Previously we used zunionInterGetKeys(), however after this function was
fixed to account for the destination key (not needed when the API was
designed for "diskstore") the two set of commands can no longer be served
by an unique keys-extraction function.
  • Loading branch information...
1 parent caf7b9b commit c0e818ab080f8c07eb1885945eea4a42f3ca3d29 @antirez committed Mar 10, 2014
Showing with 26 additions and 2 deletions.
  1. +23 −0 src/db.c
  2. +2 −2 src/redis.c
  3. +1 −0 src/redis.h
View
@@ -998,6 +998,29 @@ int *zunionInterGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *nu
return keys;
}
+/* Helper function to extract keys from the following commands:
+ * EVAL <script> <num-keys> <key> <key> ... <key> [more stuff]
+ * EVALSHA <script> <num-keys> <key> <key> ... <key> [more stuff] */
+int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) {
+ int i, num, *keys;
+ REDIS_NOTUSED(cmd);
+
+ num = atoi(argv[2]->ptr);
+ /* Sanity check. Don't return any key if the command is going to
+ * reply with syntax error. */
+ if (num > (argc-3)) {
+ *numkeys = 0;
+ return NULL;
+ }
+
+ keys = zmalloc(sizeof(int)*num);
+
+ /* Add all key positions for argv[3...n] to keys[] */
+ for (i = 0; i < num; i++) keys[i] = 3+i;
+
+ return keys;
+}
+
/* Slot to Key API. This is used by Redis Cluster in order to obtain in
* a fast way a key that belongs to a specified hash slot. This is useful
* while rehashing the cluster. */
View
@@ -259,8 +259,8 @@ struct redisCommand redisCommandTable[] = {
{"dump",dumpCommand,2,"ar",0,NULL,1,1,1,0,0},
{"object",objectCommand,-2,"r",0,NULL,2,2,2,0,0},
{"client",clientCommand,-2,"ar",0,NULL,0,0,0,0,0},
- {"eval",evalCommand,-3,"s",0,zunionInterGetKeys,0,0,0,0,0},
- {"evalsha",evalShaCommand,-3,"s",0,zunionInterGetKeys,0,0,0,0,0},
+ {"eval",evalCommand,-3,"s",0,evalGetKeys,0,0,0,0,0},
+ {"evalsha",evalShaCommand,-3,"s",0,evalGetKeys,0,0,0,0,0},
{"slowlog",slowlogCommand,-2,"r",0,NULL,0,0,0,0,0},
{"script",scriptCommand,-2,"ras",0,NULL,0,0,0,0,0},
{"time",timeCommand,1,"rR",0,NULL,0,0,0,0,0},
View
@@ -1240,6 +1240,7 @@ int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor);
int *getKeysFromCommand(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
void getKeysFreeResult(int *result);
int *zunionInterGetKeys(struct redisCommand *cmd,robj **argv, int argc, int *numkeys);
+int *evalGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
/* Cluster */
void clusterInit(void);

0 comments on commit c0e818a

Please sign in to comment.