From a7d898334afea5593a67a8633a0c8b7e7cb8ab62 Mon Sep 17 00:00:00 2001 From: antirez Date: Fri, 8 Sep 2017 11:51:53 +0200 Subject: [PATCH] Streams: XREAD get-key method fixed. --- src/db.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/db.c b/src/db.c index 8b43d4b5..e422d4b8 100644 --- a/src/db.c +++ b/src/db.c @@ -1364,8 +1364,8 @@ int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numk } /* XREAD [BLOCK ] [COUNT ] [GROUP ] - * [RETRY ] STREAMS key_1 ID_1 key_2 ID_2 ... - * key_N ID_N */ + * [RETRY ] STREAMS key_1 key_2 ... key_N + * ID_1 ID_2 ... ID_N */ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) { int i, num, *keys; UNUSED(cmd); @@ -1377,14 +1377,16 @@ int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) char *arg = argv[i]->ptr; if (!strcasecmp(arg, "streams")) streams_pos = i; } + if (streams_pos != -1) num = argc - streams_pos - 1; /* Syntax error. */ - if (streams_pos == -1) { + if (streams_pos == -1 || num % 2 != 0) { *numkeys = 0; return NULL; } + num /= 2; /* We have half the keys as there are arguments because + there are also the IDs, one per key. */ - num = argc - streams_pos - 1; keys = zmalloc(sizeof(int) * num); for (i = streams_pos+1; i < argc; i++) keys[i-streams_pos-1] = i; *numkeys = num;