Watch for the specified key */
| 295 | |
| 296 | /* Watch for the specified key */ |
| 297 | void watchForKey(client *c, robj *key) { |
| 298 | list *clients = NULL; |
| 299 | listIter li; |
| 300 | listNode *ln; |
| 301 | watchedKey *wk; |
| 302 | |
| 303 | /* Check if we are already watching for this key */ |
| 304 | listRewind(c->watched_keys,&li); |
| 305 | while((ln = listNext(&li))) { |
| 306 | wk = listNodeValue(ln); |
| 307 | if (wk->db == c->db && equalStringObjects(key,wk->key)) |
| 308 | return; /* Key already watched */ |
| 309 | } |
| 310 | /* This key is not already watched in this DB. Let's add it */ |
| 311 | clients = dictFetchValue(c->db->watched_keys,key); |
| 312 | if (!clients) { |
| 313 | clients = listCreate(); |
| 314 | dictAdd(c->db->watched_keys,key,clients); |
| 315 | incrRefCount(key); |
| 316 | } |
| 317 | listAddNodeTail(clients,c); |
| 318 | /* Add the new key to the list of keys watched by this client */ |
| 319 | wk = zmalloc(sizeof(*wk)); |
| 320 | wk->key = key; |
| 321 | wk->db = c->db; |
| 322 | incrRefCount(key); |
| 323 | listAddNodeTail(c->watched_keys,wk); |
| 324 | } |
| 325 | |
| 326 | /* Unwatch all the keys watched by this client. To clean the EXEC dirty |
| 327 | * flag is up to the caller. */ |
no test coverage detected