Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code for XREAD and XREADGROUP and add test case #187

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,29 @@ void redis_parse_cmd(struct cmd *r) {
goto error;
}

/* Skip forward to the 'startfrom' arg index. */
/* Skip forward to the 'startfrom' arg index, then search for the keyword. */
arg = arg1;
arglen = arg1_len;
while (argidx < startfrom) {
while (argidx < (int)rnarg - 1) {
if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL)
goto error; /* Keyword not provided, thus no keys. */
argidx++;
if (argidx++ < startfrom)
continue; /* Keyword can't appear in a position before 'startfrom' */
if (!strncasecmp(keyword, arg, arglen)) {
/* Keyword found. Now the first key is the next arg. */
zuiderkwast marked this conversation as resolved.
Show resolved Hide resolved
if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL)
goto error;
struct keypos *kpos = hiarray_push(r->keys);
if (kpos == NULL)
goto oom;
kpos->start = arg;
kpos->end = arg + arglen;
goto done;
}
}

/* Check that we found the keyword. */
if (strncasecmp(keyword, arg, arglen))
goto error;

/* Now find key is the next arg. */
if ((p = redis_parse_bulk(p, end, &arg, &arglen)) == NULL)
goto error;
struct keypos *kpos = hiarray_push(r->keys);
if (kpos == NULL)
goto oom;
kpos->start = arg;
kpos->end = arg + arglen;
goto done;
/* Keyword not provided. */
goto error;
}

/* Find first key arg. */
Expand Down
12 changes: 12 additions & 0 deletions tests/ut_parse_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,17 @@ void test_redis_parse_cmd_xgroup_destroy_ok(void) {
command_destroy(c);
}

void test_redis_parse_cmd_xreadgroup_ok(void) {
struct cmd *c = command_get();
int len = redisFormatCommand(
&c->cmd, "XREADGROUP GROUP XX XX COUNT 1 STREAMS mystream >");
ASSERT_MSG(len >= 0, "Format command error");
c->clen = len;
redis_parse_cmd(c);
ASSERT_KEYS(c, "mystream");
command_destroy(c);
}

int main(void) {
test_redis_parse_error_nonresp();
test_redis_parse_cmd_get();
Expand All @@ -140,5 +151,6 @@ int main(void) {
test_redis_parse_cmd_xgroup_no_subcommand();
test_redis_parse_cmd_xgroup_destroy_no_key();
test_redis_parse_cmd_xgroup_destroy_ok();
test_redis_parse_cmd_xreadgroup_ok();
return 0;
}