Skip to content

Commit 40cbc65

Browse files
committed
Use the correct command proc for the LOOKUP_NOTOUCH exception in lookupKey
When looking up a key in no-touch mode, `LOOKUP_NOTOUCH` is set to avoid updating the last access time in `lookupKey`. An exception must be made for the `TOUCH` command which must always update the key. When called from a script, `server.executing_client` will point to the `TOUCH` command, while `server.current_client` will point to e.g. an `EVAL` command. So, we must use the former to find out the currently executing command if defined. This fix addresses the issue where TOUCH wasn't updating key access times when called from scripts like EVAL. Fixes #1498 Signed-off-by: Simon Baatz <[email protected]>
1 parent a136ad9 commit 40cbc65

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/db.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ robj *lookupKey(serverDb *db, robj *key, int flags) {
123123
/* Update the access time for the ageing algorithm.
124124
* Don't do it if we have a saving child, as this will trigger
125125
* a copy on write madness. */
126+
client *executing_client = (server.executing_client) ? server.executing_client : server.current_client;
126127
if (server.current_client && server.current_client->flag.no_touch &&
127-
server.current_client->cmd->proc != touchCommand)
128+
executing_client->cmd->proc != touchCommand)
128129
flags |= LOOKUP_NOTOUCH;
129130
if (!hasActiveChildProcess() && !(flags & LOOKUP_NOTOUCH)) {
130131
/* Shared objects can't be stored in the database. */

tests/unit/introspection-2.tcl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,24 @@ start_server {tags {"introspection"}} {
3030
assert {[r object idletime foo] >= 2}
3131
}
3232

33-
test {TOUCH alters the last access time of a key} {
33+
proc test_touch_alters_access_time {} {
3434
r set foo bar
35+
r set script_foo bar
3536
after 3000
3637
r touch foo
38+
r eval {redis.call('touch', KEYS[1])} 1 script_foo
3739
assert {[r object idletime foo] < 2}
40+
assert {[r object idletime script_foo] < 2}
41+
}
42+
43+
test {TOUCH alters the last access time of a key} {
44+
test_touch_alters_access_time
45+
}
46+
47+
test {TOUCH alters the last access time of a key in no-touch mode} {
48+
r client no-touch on
49+
test_touch_alters_access_time
50+
r client no-touch off
3851
}
3952

4053
test {Operations in no-touch mode do not alter the last access time of a key} {

0 commit comments

Comments
 (0)