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

Function trackingBuildBroadcastReply

src/tracking.cpp:501–541  ·  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

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