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