How to fix READONLY You can't write against a read only replica in Redis

RedisINTERMEDIATEHIGHUpdated Dec 25, 2025· 155 views

This error occurs when your application attempts a write operation on a Redis replica instead of the primary master node. Redis replicas are read-only by default to prevent accidental data corruption.

Quick fix

Fixes READONLY You can't write against a read only replica

redis-cli
> INFO REPLICATION
  1. Identify if you're connected to a replica
  2. Verify the master address
  3. Update your application connection string
  4. For managed Redis services, use the primary endpoint
redis — error
redis-cli
> INFO REPLICATION
READONLY You can't write against a read only replica

What this error means

In a Redis replication setup, the primary node (master) handles all write operations while replica nodes sync data and serve read-only requests. When you try to write to a replica, Redis rejects the command with this error. This is a safety mechanism because replicas should only mirror the master's data, not create independent modifications that would cause inconsistency.

Typical symptoms

  • Redis SET, DEL, INCR, or other write commands fail with the READONLY error
  • Application cache writes stop working intermittently or consistently
  • Error appears in logs after cluster failover or DNS changes
  • Only read operations (GET, SCAN, etc.) work successfully

Common causes

  1. Application is connected to a replica node instead of the master node
  2. Failover event changed the master, but application still connects to old node
  3. DNS caching in client library routes requests to wrong node
  4. Redis configuration has replica-read-only enabled (default behavior)
  5. Connection string points to read-only endpoint in managed Redis service
  6. Client library retry logic chose a replica after network timeout

How to fix "READONLY You can't write against a read only replica"

1Identify if you're connected to a replica

Connect to your Redis instance and check its role:

bash
redis-cli
> INFO REPLICATION

Look for the role field. If it shows role:slave, you're on a replica. If it shows role:master, the replica-read-only setting is the issue.

2Verify the master address

Get the master node's address from the replica:

bash
> INFO REPLICATION
master_host:127.0.0.1
master_port:6379

Note the master's host and port. You should connect your application here for write operations.

3Update your application connection string

Change your Redis client to connect to the master node's address:

Node.js example:

javascript
const redis = require('redis');
const client = redis.createClient({
  host: 'master-node-ip',  // Use master, not replica
  port: 6379
});

Python example:

python
import redis
r = redis.Redis(host='master-node-ip', port=6379, db=0)

Verify with a test write:

bash
r.set('test-key', 'value')
4For managed Redis services, use the primary endpoint

If using AWS ElastiCache, Google Cloud Memorystore, or Azure Cache:

1. Open your Redis service console
2. Find the primary/master endpoint (not read-replica endpoint)
3. Update your application configuration to use this endpoint

Example AWS ElastiCache:
- Use: my-redis-cluster.abc123.ng.0001.use1.cache.amazonaws.com:6379
- NOT: my-redis-replica.abc123.ng.0001.use1.cache.amazonaws.com:6379

5If you must promote the replica to master (advanced)

Only do this if the original master is permanently down and you understand the implications:

bash
redis-cli
> SLAVEOF NO ONE

This makes the replica a standalone master. Use with caution as you may lose recent writes if the original master was still running.

6Configure DNS/connection pooling to stick to master

If using Redis Sentinel or Cluster mode:

For Sentinel:
- Connect to sentinel port (26379) and query for master
- Let the client library handle master discovery
- Ensure your client supports sentinel protocol

For Cluster:
- Use a cluster-aware client library
- Set cluster-enabled yes in redis.conf only on cluster nodes
- Let the client discover all nodes and send writes to slots' owners

Connection pooling tip:

javascript
// Bad: Creates new connection per request
const client = redis.createClient({host: 'master'});

// Good: Reuse connection pool
const pool = redis.createPool({host: 'master', max: 10});

Advanced notes

Replica Read-Only Mode: The replica-read-only config parameter (default: yes) controls whether replicas reject writes. You can disable it with CONFIG SET replica-read-only no at runtime, but this is NOT recommended because writable replicas create consistency issues.

DNS and Connection Caching: Some Redis clients cache DNS results or connection objects. If your master changes, the cache may still point to old nodes. Solutions: disable DNS caching in your client, use Redis Sentinel for automatic failover, or implement application-level health checks.

Failover and Retry Logic: After failover, client libraries might retry failed commands on random nodes (including replicas). If a write command times out during failover, the retry might hit a replica, causing this error. Use client libraries with master-aware retry logic.

Cluster vs Replication: In Redis Cluster mode, each slot has a master and replicas. Writes must go to the slot's master. The readonly command allows a client to read from replicas, but writes always fail on replicas even with it enabled.

Frequently asked questions

What does "READONLY You can't write against a read only replica" mean?
In a Redis replication setup, the primary node (master) handles all write operations while replica nodes sync data and serve read-only requests. When you try to write to a replica, Redis rejects the command with this error. This is a safety mechanism because replicas should only mirror the master's data, not create independent modifications that would cause inconsistency.
How do I fix "READONLY You can't write against a read only replica"?
This error occurs when your application attempts a write operation on a Redis replica instead of the primary master node. Redis replicas are read-only by default to prevent accidental data corruption.
What causes "READONLY You can't write against a read only replica"?
Application is connected to a replica node instead of the master node Failover event changed the master, but application still connects to old node DNS caching in client library routes requests to wrong node
Is the "READONLY You can't write against a read only replica" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading