# CLIENT NO-EVICT

> Exempt the current connection from being closed when clients hold more than maxmemory-clients.

URL: https://docs.hotkv.com/commands/client-no-evict/

```
CLIENT NO-EVICT ON | OFF
```

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

When [`maxmemory-clients`](https://docs.hotkv.com/reference/configuration/index.md#maxmemory-clients) is set
and the clients together hold more than it allows, HotKV closes the clients that
hold the most. `CLIENT NO-EVICT ON` exempts the current connection from that, and
`OFF` removes the exemption. While it is on, the connection shows the `e` flag in
[CLIENT LIST](https://docs.hotkv.com/commands/client-list/index.md). Use it for a connection that must stay up,
such as an administration session.

An exempt connection's memory still counts toward the total. If it is the one
that holds too much, the clients that can be evicted are closed in its place, the
largest first. Turning it off judges the clients at once, so the connection
itself may be closed if it is the largest.

A replica's link, a connection of an atomic slot migration and another cluster
node's own connection are never evicted and not counted, whatever this says.
[RESET](https://docs.hotkv.com/commands/reset/index.md) turns the exemption off. See
[Client memory](https://docs.hotkv.com/operate/memory-and-eviction/index.md#client-memory).

## Return value

| Case | Reply (RESP2 and RESP3) |
| --- | --- |
| `ON` or `OFF` | Simple string `OK` |
| Any other value | Error `ERR syntax error` |

## Examples

```
127.0.0.1:6379> CLIENT NO-EVICT ON
OK
127.0.0.1:6379> CLIENT NO-EVICT maybe
(error) ERR syntax error
```

## Compatibility

Same replies as Redis 7 and Valkey 8. Evictions are counted in the
`evicted_clients` field of [INFO](https://docs.hotkv.com/commands/info/index.md) `stats`.

## See also

[CLIENT NO-TOUCH](https://docs.hotkv.com/commands/client-no-touch/index.md), [CLIENT LIST](https://docs.hotkv.com/commands/client-list/index.md),
[Memory and eviction](https://docs.hotkv.com/operate/memory-and-eviction/index.md)