# READONLY

> Let a cluster client read keys from a replica instead of being redirected to the primary.

URL: https://docs.hotkv.com/commands/readonly/

```
READONLY
```

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

In a cluster, a replica normally answers every command on a key with
`-MOVED` to its primary. After `READONLY`, the connection may read keys of the
slots its replica's primary serves directly from the replica, which spreads
read load across the replicas. Writes still get `-MOVED` to the primary.

Data read from a replica can be slightly behind the primary, since
replication is asynchronous. The setting lasts for the connection until
[READWRITE](https://docs.hotkv.com/commands/readwrite/index.md) or the connection closes.

## Return value

Simple string `OK` in RESP2 and RESP3. With cluster mode off:
`ERR This instance has cluster support disabled`.

## Examples

```
10.0.0.4:6379> GET user:1000
(error) MOVED 1649 10.0.0.1:6379
10.0.0.4:6379> READONLY
OK
10.0.0.4:6379> GET user:1000
"alice"
10.0.0.4:6379> SET user:1000 "bob"
(error) MOVED 1649 10.0.0.1:6379
```

## Compatibility

Same as Redis 7 and Valkey 8.

## See also

[READWRITE](https://docs.hotkv.com/commands/readwrite/index.md), [ASKING](https://docs.hotkv.com/commands/asking/index.md),
[CLUSTER SLOTS](https://docs.hotkv.com/commands/cluster-slots/index.md)

In a cluster: [Keys, slots and commands in a cluster](https://docs.hotkv.com/clustering/keys-and-commands/index.md#reading-from-replicas)