This function is called when a key is modified in Redis and in the case * we have at least one client with the BCAST mode enabled. * Its goal is to set the key in the right broadcast state if the key * matches one or more prefixes in the prefix table. Later when we * return to the event loop, we'll send invalidation messages to the * clients subscribed to each prefix. */
| 314 | * return to the event loop, we'll send invalidation messages to the |
| 315 | * clients subscribed to each prefix. */ |
| 316 | void trackingRememberKeyToBroadcast(client *c, char *keyname, size_t keylen) { |
| 317 | raxIterator ri; |
| 318 | raxStart(&ri,PrefixTable); |
| 319 | raxSeek(&ri,"^",NULL,0); |
| 320 | while(raxNext(&ri)) { |
| 321 | if (ri.key_len > keylen) continue; |
| 322 | if (ri.key_len != 0 && memcmp(ri.key,keyname,ri.key_len) != 0) |
| 323 | continue; |
| 324 | bcastState *bs = ri.data; |
| 325 | /* We insert the client pointer as associated value in the radix |
| 326 | * tree. This way we know who was the client that did the last |
| 327 | * change to the key, and can avoid sending the notification in the |
| 328 | * case the client is in NOLOOP mode. */ |
| 329 | raxInsert(bs->keys,(unsigned char*)keyname,keylen,c,NULL); |
| 330 | } |
| 331 | raxStop(&ri); |
| 332 | } |
| 333 | |
| 334 | /* This function is called from signalModifiedKey() or other places in Redis |
| 335 | * when a key changes value. In the context of keys tracking, our task here is |