diff --git a/src/db.c b/src/db.c index 12559f3e293..192f22e9799 100644 --- a/src/db.c +++ b/src/db.c @@ -115,8 +115,9 @@ robj *lookupKey(serverDb *db, robj *key, int flags) { /* Update the access time for the ageing algorithm. * Don't do it if we have a saving child, as this will trigger * a copy on write madness. */ - if (server.current_client && server.current_client->flag.no_touch && server.executing_client && - server.executing_client->cmd->proc != touchCommand) + if ((flags & LOOKUP_NOTOUCH) == 0 && + server.current_client && server.current_client->flag.no_touch && + server.executing_client && server.executing_client->cmd->proc != touchCommand) flags |= LOOKUP_NOTOUCH; if (!hasActiveChildProcess() && !(flags & LOOKUP_NOTOUCH)) { /* Shared objects can't be stored in the database. */ diff --git a/tests/unit/type/list.tcl b/tests/unit/type/list.tcl index 3382cc611cd..faeb8e1675b 100644 --- a/tests/unit/type/list.tcl +++ b/tests/unit/type/list.tcl @@ -2453,4 +2453,36 @@ foreach {pop} {BLPOP BLMPOP_RIGHT} { $rd close } + test "CLIENT NO-TOUCH with BRPOP and RPUSH regression test" { + # Test scenario: + # 1. Client 1: CLIENT NO-TOUCH on + # 2. Client 2: BRPOP mylist 0 + # 3. Client 1: RPUSH mylist elem + + # cleanup first + r del mylist + + # Create two test clients + set rd1 [valkey_deferring_client] + set rd2 [valkey_deferring_client] + + # Client 1: Enable CLIENT NO-TOUCH + $rd1 client no-touch on + assert_equal {OK} [$rd1 read] + + # Client 2: Block waiting for elements in mylist + $rd2 brpop mylist 0 + wait_for_blocked_client + + # Client 1: Push an element to mylist + $rd1 rpush mylist elem + assert_equal {1} [$rd1 read] + + # Verify Client 2 received the element + assert_equal {mylist elem} [$rd2 read] + + $rd1 close + $rd2 close + } + } ;# stop servers