XGROUP CREATE [MKSTREAM] * XGROUP SETID * XGROUP DESTROY * XGROUP CREATECONSUMER * XGROUP DELCONSUMER */
| 2354 | * XGROUP CREATECONSUMER <key> <groupname> <consumer> |
| 2355 | * XGROUP DELCONSUMER <key> <groupname> <consumername> */ |
| 2356 | void xgroupCommand(client *c) { |
| 2357 | stream *s = NULL; |
| 2358 | sds grpname = NULL; |
| 2359 | streamCG *cg = NULL; |
| 2360 | char *opt = c->argv[1]->ptr; /* Subcommand name. */ |
| 2361 | int mkstream = 0; |
| 2362 | robj *o; |
| 2363 | |
| 2364 | /* CREATE has an MKSTREAM option that creates the stream if it |
| 2365 | * does not exist. */ |
| 2366 | if (c->argc == 6 && !strcasecmp(opt,"CREATE")) { |
| 2367 | if (strcasecmp(c->argv[5]->ptr,"MKSTREAM")) { |
| 2368 | addReplySubcommandSyntaxError(c); |
| 2369 | return; |
| 2370 | } |
| 2371 | mkstream = 1; |
| 2372 | grpname = c->argv[3]->ptr; |
| 2373 | } |
| 2374 | |
| 2375 | /* Everything but the "HELP" option requires a key and group name. */ |
| 2376 | if (c->argc >= 4) { |
| 2377 | o = lookupKeyWrite(c->db,c->argv[2]); |
| 2378 | if (o) { |
| 2379 | if (checkType(c,o,OBJ_STREAM)) return; |
| 2380 | s = o->ptr; |
| 2381 | } |
| 2382 | grpname = c->argv[3]->ptr; |
| 2383 | } |
| 2384 | |
| 2385 | /* Check for missing key/group. */ |
| 2386 | if (c->argc >= 4 && !mkstream) { |
| 2387 | /* At this point key must exist, or there is an error. */ |
| 2388 | if (s == NULL) { |
| 2389 | addReplyError(c, |
| 2390 | "The XGROUP subcommand requires the key to exist. " |
| 2391 | "Note that for CREATE you may want to use the MKSTREAM " |
| 2392 | "option to create an empty stream automatically."); |
| 2393 | return; |
| 2394 | } |
| 2395 | |
| 2396 | /* Certain subcommands require the group to exist. */ |
| 2397 | if ((cg = streamLookupCG(s,grpname)) == NULL && |
| 2398 | (!strcasecmp(opt,"SETID") || |
| 2399 | !strcasecmp(opt,"CREATECONSUMER") || |
| 2400 | !strcasecmp(opt,"DELCONSUMER"))) |
| 2401 | { |
| 2402 | addReplyErrorFormat(c, "-NOGROUP No such consumer group '%s' " |
| 2403 | "for key name '%s'", |
| 2404 | (char*)grpname, (char*)c->argv[2]->ptr); |
| 2405 | return; |
| 2406 | } |
| 2407 | } |
| 2408 | |
| 2409 | /* Dispatch the different subcommands. */ |
| 2410 | if (c->argc == 2 && !strcasecmp(opt,"HELP")) { |
| 2411 | const char *help[] = { |
| 2412 | "CREATE <key> <groupname> <id|$> [option]", |
| 2413 | " Create a new consumer group. Options are:", |
nothing calls this directly
no test coverage detected