summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2015-12-11 18:09:01 +0100
committerantirez <antirez@gmail.com>2015-12-13 10:17:40 +0100
commit170adbf2c4dfe51f0c7ae8ece6ee4ab76fafa11f (patch)
tree41ad3697c37dc51287a741ede97584cbf28a370e
parent8a02f61b273691f95b0fe1cd5ca79d6e7a03e6ba (diff)
downloadredis-170adbf2c4dfe51f0c7ae8ece6ee4ab76fafa11f.tar.gz
MIGRATE: Fix key extraction for new form.
-rw-r--r--src/db.c27
-rw-r--r--src/redis.c2
-rw-r--r--src/redis.h1
3 files changed, 29 insertions, 1 deletions
diff --git a/src/db.c b/src/db.c
index c74cde248..b4788e931 100644
--- a/src/db.c
+++ b/src/db.c
@@ -1131,6 +1131,33 @@ int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys)
return keys;
}
+int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) {
+ int i, num, first, *keys;
+ UNUSED(cmd);
+
+ /* Assume the obvious form. */
+ first = 3;
+ num = 1;
+
+ /* But check for the extended one with the KEYS option. */
+ if (argc > 6) {
+ for (i = 6; i < argc; i++) {
+ if (!strcasecmp(argv[i]->ptr,"keys") &&
+ sdslen(argv[3]->ptr) == 0)
+ {
+ first = i+1;
+ num = argc-first;
+ break;
+ }
+ }
+ }
+
+ keys = zmalloc(sizeof(int)*num);
+ for (i = 0; i < num; i++) keys[i] = first+i;
+ *numkeys = num;
+ 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. */
diff --git a/src/redis.c b/src/redis.c
index 3afe1601d..b781ebd64 100644
--- a/src/redis.c
+++ b/src/redis.c
@@ -261,7 +261,7 @@ struct redisCommand redisCommandTable[] = {
{"cluster",clusterCommand,-2,"ar",0,NULL,0,0,0,0,0},
{"restore",restoreCommand,-4,"wm",0,NULL,1,1,1,0,0},
{"restore-asking",restoreCommand,-4,"wmk",0,NULL,1,1,1,0,0},
- {"migrate",migrateCommand,-6,"w",0,NULL,3,3,1,0,0},
+ {"migrate",migrateCommand,-6,"w",0,migrateGetKeys,0,0,0,0,0},
{"asking",askingCommand,1,"r",0,NULL,0,0,0,0,0},
{"readonly",readonlyCommand,1,"rF",0,NULL,0,0,0,0,0},
{"readwrite",readwriteCommand,1,"rF",0,NULL,0,0,0,0,0},
diff --git a/src/redis.h b/src/redis.h
index 8e63f6c5b..76a707c11 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -1361,6 +1361,7 @@ 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);
int *sortGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
+int *migrateGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys);
/* Cluster */
void clusterInit(void);