# OBJECT IDLETIME

> Return how many seconds have passed since a key was last accessed.

URL: https://docs.hotkv.com/commands/object-idletime/

```
OBJECT IDLETIME key
```

- Group: Keys
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`OBJECT IDLETIME` returns the number of seconds since `key` was last read or
written. LRU-based eviction policies use this idle time to choose keys to
evict. Commands that only inspect a key (such as `OBJECT`, [TYPE](https://docs.hotkv.com/commands/type/index.md),
[TTL](https://docs.hotkv.com/commands/ttl/index.md) and [EXISTS](https://docs.hotkv.com/commands/exists/index.md)) do not reset it, while
[TOUCH](https://docs.hotkv.com/commands/touch/index.md) does.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| The key exists | Integer: idle seconds | Integer |
| The key does not exist | Nil bulk string | Null |

While an LFU eviction policy is selected the idle time is not tracked, and the
reply is the error
`ERR An LFU maxmemory policy is selected, idle time not tracked.` followed by
a note that switching policies at runtime takes a while to settle.

## Examples

```
127.0.0.1:6379> SET report "q3"
OK
127.0.0.1:6379> OBJECT IDLETIME report
(integer) 0
127.0.0.1:6379> OBJECT IDLETIME report
(integer) 42
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[OBJECT FREQ](https://docs.hotkv.com/commands/object-freq/index.md), [TOUCH](https://docs.hotkv.com/commands/touch/index.md),
[OBJECT](https://docs.hotkv.com/commands/object/index.md)