a little optimization in touchAllWatchedKeysInDb (#9200)

touch keys only if the key is in one of the dbs,
in case rewind the list when the key doesn't exist.
This commit is contained in:
zhaozhao.zz 2021-07-06 15:01:37 +08:00 committed by GitHub
parent f06d782f5a
commit 5ea3c3db15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -380,14 +380,14 @@ void touchAllWatchedKeysInDb(redisDb *emptied, redisDb *replaced_with) {
dictIterator *di = dictGetSafeIterator(emptied->watched_keys);
while((de = dictNext(di)) != NULL) {
robj *key = dictGetKey(de);
list *clients = dictGetVal(de);
if (!clients) continue;
listRewind(clients,&li);
while((ln = listNext(&li))) {
client *c = listNodeValue(ln);
if (dictFind(emptied->dict, key->ptr)) {
c->flags |= CLIENT_DIRTY_CAS;
} else if (replaced_with && dictFind(replaced_with->dict, key->ptr)) {
if (dictFind(emptied->dict, key->ptr) ||
(replaced_with && dictFind(replaced_with->dict, key->ptr)))
{
list *clients = dictGetVal(de);
if (!clients) continue;
listRewind(clients,&li);
while((ln = listNext(&li))) {
client *c = listNodeValue(ln);
c->flags |= CLIENT_DIRTY_CAS;
}
}