mirror of
https://github.com/fluencelabs/redis
synced 2025-03-18 00:20:50 +00:00
Streams: fix xreadGetKeys() for correctness.
The old version could not handle the fact that "STREAMS" is a valid key name for streams. Now we really try to parse the command like the command implementation would do. Related to #5028 and 4857.
This commit is contained in:
parent
e670ccffea
commit
2076660843
24
src/db.c
24
src/db.c
@ -1398,18 +1398,32 @@ int *georadiusGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numk
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* XREAD [BLOCK <milliseconds>] [COUNT <count>] [GROUP <groupname> <ttl>]
|
/* XREAD [BLOCK <milliseconds>] [COUNT <count>] [GROUP <groupname> <ttl>]
|
||||||
* [RETRY <milliseconds> <ttl>] STREAMS key_1 key_2 ... key_N
|
* STREAMS key_1 key_2 ... key_N ID_1 ID_2 ... ID_N */
|
||||||
* ID_1 ID_2 ... ID_N */
|
|
||||||
int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) {
|
int *xreadGetKeys(struct redisCommand *cmd, robj **argv, int argc, int *numkeys) {
|
||||||
int i, num, *keys;
|
int i, num, *keys;
|
||||||
UNUSED(cmd);
|
UNUSED(cmd);
|
||||||
|
|
||||||
/* We need to seek the last argument that contains "STREAMS", because other
|
/* We need to parse the options of the command in order to seek the first
|
||||||
* arguments before may contain it (for example the group name). */
|
* "STREAMS" string which is actually the option. This is needed because
|
||||||
|
* "STREAMS" could also be the name of the consumer group and even the
|
||||||
|
* name of the stream key. */
|
||||||
int streams_pos = -1;
|
int streams_pos = -1;
|
||||||
for (i = 1; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
char *arg = argv[i]->ptr;
|
char *arg = argv[i]->ptr;
|
||||||
if (!strcasecmp(arg, "streams")) streams_pos = i;
|
if (!strcasecmp(arg, "block")) {
|
||||||
|
i++; /* Skip option argument. */
|
||||||
|
} else if (!strcasecmp(arg, "count")) {
|
||||||
|
i++; /* Skip option argument. */
|
||||||
|
} else if (!strcasecmp(arg, "group")) {
|
||||||
|
i += 2; /* Skip option argument. */
|
||||||
|
} else if (!strcasecmp(arg, "noack")) {
|
||||||
|
/* Nothing to do. */
|
||||||
|
} else if (!strcasecmp(arg, "streams")) {
|
||||||
|
streams_pos = i;
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
break; /* Syntax error. */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (streams_pos != -1) num = argc - streams_pos - 1;
|
if (streams_pos != -1) num = argc - streams_pos - 1;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user