Set CLIENT_DIRTY_CAS to all clients of DB when DB is dirty. * It may happen in the following situations: * FLUSHDB, FLUSHALL, SWAPDB * * replaced_with: for SWAPDB, the WATCH should be invalidated if * the key exists in either of them, and skipped only if it * doesn't exist in both. */
| 396 | * the key exists in either of them, and skipped only if it |
| 397 | * doesn't exist in both. */ |
| 398 | void touchAllWatchedKeysInDb(redisDb *emptied, redisDb *replaced_with) { |
| 399 | listIter li; |
| 400 | listNode *ln; |
| 401 | dictEntry *de; |
| 402 | |
| 403 | if (dictSize(emptied->watched_keys) == 0) return; |
| 404 | |
| 405 | dictIterator *di = dictGetSafeIterator(emptied->watched_keys); |
| 406 | while((de = dictNext(di)) != NULL) { |
| 407 | robj *key = dictGetKey(de); |
| 408 | list *clients = dictGetVal(de); |
| 409 | if (!clients) continue; |
| 410 | listRewind(clients,&li); |
| 411 | while((ln = listNext(&li))) { |
| 412 | client *c = listNodeValue(ln); |
| 413 | if (dictFind(emptied->dict, key->ptr)) { |
| 414 | c->flags |= CLIENT_DIRTY_CAS; |
| 415 | } else if (replaced_with && dictFind(replaced_with->dict, key->ptr)) { |
| 416 | c->flags |= CLIENT_DIRTY_CAS; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | dictReleaseIterator(di); |
| 421 | } |
| 422 | |
| 423 | void watchCommand(client *c) { |
| 424 | int j; |
no test coverage detected