You can't write against a read only replica
Production Risk
Medium. While it prevents data corruption, it indicates a misconfiguration that can block application functionality.
This error occurs when a client attempts to execute a write command (e.g., SET, DEL, INCR) against a Redis instance that is configured as a read-only replica. Replicas mirror the data from a primary instance and, by default, do not accept writes.
- 1Application is incorrectly configured to send write traffic to a replica's address instead of the primary's.
- 2In a failover scenario, a client has not yet updated its connection to the newly promoted primary.
- 3A Redis Sentinel or Cluster setup is misconfigured, leading clients to connect to the wrong node for writes.
An application, by mistake, connects to a replica instance and tries to set a key.
# On a replica instance SET newkey "somevalue"
expected output
(error) READONLY You can't write against a read only replica.
Fix 1
Correct the client configuration
WHEN This is the most common cause
// In application config
const redis_config = {
host: "redis-primary.example.com", // Not redis-replica.example.com
port: 6379
};Why this works
Ensure all clients performing write operations are configured with the network address of the primary Redis instance.
Fix 2
Use Redis Sentinel or Cluster for automatic failover
WHEN To build a robust, high-availability architecture
# Sentinel provides the current primary's address redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
Why this works
High-availability solutions like Sentinel or Redis Cluster manage the identity of the primary instance. Clients should query the HA system to discover the correct node to write to, rather than using a hardcoded address.
✕ Disable the read-only setting on the replica
Setting `replica-read-only no` breaks the replication consistency model. Writes to the replica will not be propagated and will be overwritten by data from the primary, leading to data loss and inconsistency.
Replica configuration and command processing logic
Redis Sentinel Documentation ↗Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev