MCPcopy Create free account
hub / github.com/F-Stack/f-stack / trackingBuildBroadcastReply

Function trackingBuildBroadcastReply

app/redis-6.2.6/src/tracking.c:497–537  ·  view source on GitHub ↗

Generate Redis protocol for an array containing all the key names * in the 'keys' radix tree. If the client is not NULL, the list will not * include keys that were modified the last time by this client, in order * to implement the NOLOOP option. * * If the resultin array would be empty, NULL is returned instead. */

Source from the content-addressed store, hash-verified

495 *
496 * If the resultin array would be empty, NULL is returned instead. */
497sds trackingBuildBroadcastReply(client *c, rax *keys) {
498 raxIterator ri;
499 uint64_t count;
500
501 if (c == NULL) {
502 count = raxSize(keys);
503 } else {
504 count = 0;
505 raxStart(&ri,keys);
506 raxSeek(&ri,"^",NULL,0);
507 while(raxNext(&ri)) {
508 if (ri.data != c) count++;
509 }
510 raxStop(&ri);
511
512 if (count == 0) return NULL;
513 }
514
515 /* Create the array reply with the list of keys once, then send
516 * it to all the clients subscribed to this prefix. */
517 char buf[32];
518 size_t len = ll2string(buf,sizeof(buf),count);
519 sds proto = sdsempty();
520 proto = sdsMakeRoomFor(proto,count*15);
521 proto = sdscatlen(proto,"*",1);
522 proto = sdscatlen(proto,buf,len);
523 proto = sdscatlen(proto,"\r\n",2);
524 raxStart(&ri,keys);
525 raxSeek(&ri,"^",NULL,0);
526 while(raxNext(&ri)) {
527 if (c && ri.data == c) continue;
528 len = ll2string(buf,sizeof(buf),ri.key_len);
529 proto = sdscatlen(proto,"$",1);
530 proto = sdscatlen(proto,buf,len);
531 proto = sdscatlen(proto,"\r\n",2);
532 proto = sdscatlen(proto,ri.key,ri.key_len);
533 proto = sdscatlen(proto,"\r\n",2);
534 }
535 raxStop(&ri);
536 return proto;
537}
538
539/* This function will run the prefixes of clients in BCAST mode and
540 * keys that were modified about each prefix, and will send the

Callers 1

Calls 9

raxSizeFunction · 0.85
raxStartFunction · 0.85
raxSeekFunction · 0.85
raxNextFunction · 0.85
raxStopFunction · 0.85
ll2stringFunction · 0.85
sdsemptyFunction · 0.85
sdsMakeRoomForFunction · 0.85
sdscatlenFunction · 0.85

Tested by

no test coverage detected