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