From 6444214ce4d032b75b0dac7d579f385ead58850c Mon Sep 17 00:00:00 2001 From: Qu Chen Date: Sun, 29 Jan 2023 18:00:24 -0800 Subject: [PATCH] Fix master client check in expireIfNeeded() for read only replica (#11761) Redis 7.0 introduced new logic in expireIfNeeded() where a read-only replica would never consider a key as expired when replicating commands from the master. See acf3495. This was done by checking server.current_client with server.master. However, we should instead check for CLIENT_MASTER flag for this logic to be more robust and consistent with the rest of the Redis code base. --- src/db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.c b/src/db.c index e397183c9..f07c8910d 100644 --- a/src/db.c +++ b/src/db.c @@ -1708,7 +1708,7 @@ int expireIfNeeded(redisDb *db, robj *key, int flags) { * When replicating commands from the master, keys are never considered * expired. */ if (server.masterhost != NULL) { - if (server.current_client == server.master) return 0; + if (server.current_client && (server.current_client->flags & CLIENT_MASTER)) return 0; if (!(flags & EXPIRE_FORCE_DELETE_EXPIRED)) return 1; }