READONLY
RedisERRORCriticalReplicationHIGH confidence

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.

What this means

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.

Why it happens
  1. 1Application is incorrectly configured to send write traffic to a replica's address instead of the primary's.
  2. 2In a failover scenario, a client has not yet updated its connection to the newly promoted primary.
  3. 3A Redis Sentinel or Cluster setup is misconfigured, leading clients to connect to the wrong node for writes.
How to reproduce

An application, by mistake, connects to a replica instance and tries to set a key.

trigger — this will error
trigger — this will error
# 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

Correct the client configuration
// 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

Use Redis Sentinel or Cluster for automatic failover
# 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.

What not to do

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.

Sources
Official documentation ↗

Replica configuration and command processing logic

Redis Sentinel Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Redis errors