MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / xinfoReplyWithStreamInfo

Function xinfoReplyWithStreamInfo

src/t_stream.cpp:3303–3484  ·  view source on GitHub ↗

Helper function for xinfoCommand. * Handles the variants of XINFO STREAM */

Source from the content-addressed store, hash-verified

3301/* Helper function for xinfoCommand.
3302 * Handles the variants of XINFO STREAM */
3303void xinfoReplyWithStreamInfo(client *c, stream *s) {
3304 int full = 1;
3305 long long count = 10; /* Default COUNT is 10 so we don't block the server */
3306 robj **optv = c->argv + 3; /* Options start after XINFO STREAM <key> */
3307 int optc = c->argc - 3;
3308
3309 /* Parse options. */
3310 if (optc == 0) {
3311 full = 0;
3312 } else {
3313 /* Valid options are [FULL] or [FULL COUNT <count>] */
3314 if (optc != 1 && optc != 3) {
3315 addReplySubcommandSyntaxError(c);
3316 return;
3317 }
3318
3319 /* First option must be "FULL" */
3320 if (strcasecmp(szFromObj(optv[0]),"full")) {
3321 addReplySubcommandSyntaxError(c);
3322 return;
3323 }
3324
3325 if (optc == 3) {
3326 /* First option must be "FULL" */
3327 if (strcasecmp(szFromObj(optv[1]),"count")) {
3328 addReplySubcommandSyntaxError(c);
3329 return;
3330 }
3331 if (getLongLongFromObjectOrReply(c,optv[2],&count,NULL) == C_ERR)
3332 return;
3333 if (count < 0) count = 10;
3334 }
3335 }
3336
3337 addReplyMapLen(c,full ? 6 : 7);
3338 addReplyBulkCString(c,"length");
3339 addReplyLongLong(c,s->length);
3340 addReplyBulkCString(c,"radix-tree-keys");
3341 addReplyLongLong(c,raxSize(s->rax));
3342 addReplyBulkCString(c,"radix-tree-nodes");
3343 addReplyLongLong(c,s->rax->numnodes);
3344 addReplyBulkCString(c,"last-generated-id");
3345 addReplyStreamID(c,&s->last_id);
3346
3347 if (!full) {
3348 /* XINFO STREAM <key> */
3349
3350 addReplyBulkCString(c,"groups");
3351 addReplyLongLong(c,s->cgroups ? raxSize(s->cgroups) : 0);
3352
3353 /* To emit the first/last entry we use streamReplyWithRange(). */
3354 int emitted;
3355 streamID start, end;
3356 start.ms = start.seq = 0;
3357 end.ms = end.seq = UINT64_MAX;
3358 addReplyBulkCString(c,"first-entry");
3359 emitted = streamReplyWithRange(c,s,&start,&end,1,0,NULL,NULL,
3360 STREAM_RWR_RAWENTRIES,NULL);

Callers 1

xinfoCommandFunction · 0.85

Calls 15

szFromObjFunction · 0.85
addReplyMapLenFunction · 0.85
addReplyBulkCStringFunction · 0.85
addReplyLongLongFunction · 0.85
raxSizeFunction · 0.85
addReplyStreamIDFunction · 0.85
streamReplyWithRangeFunction · 0.85
addReplyNullFunction · 0.85
addReplyArrayLenFunction · 0.85
raxStartFunction · 0.85

Tested by

no test coverage detected