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.
This commit is contained in:
Qu Chen 2023-01-29 18:00:24 -08:00 committed by GitHub
parent cc97f4cf35
commit 6444214ce4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}