# OBJECT FREQ

> Return a key's access frequency counter under an LFU eviction policy.

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

```
OBJECT FREQ key
```

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

`OBJECT FREQ` returns the logarithmic access frequency counter of `key`, from
0 to 255, that the `allkeys-lfu` and `volatile-lfu` eviction policies use to
pick keys to evict. The counter decays over time when the key is not used.
Access frequencies are tracked only while an LFU policy is selected with
`maxmemory-policy`.

## Return value

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

When the eviction policy is not an LFU one, the reply is the error
`ERR An LFU maxmemory policy is not selected, access frequency not tracked.`
followed by a note that switching policies at runtime takes a while to settle.

## Examples

```
127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lfu
OK
127.0.0.1:6379> SET page:home "..."
OK
127.0.0.1:6379> OBJECT FREQ page:home
(integer) 5
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

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