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

RedisINTERMEDIATEHIGHUpdated Dec 29, 2025ยท 200 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 design to maintain data consistency across the replication cluster.

Quick fix

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

redis-cli -h <your-redis-host> -p <your-redis-port>
> INFO REPLICATION
  1. Check if the node you're connected to is a replica
  2. Identify the master node address
  3. Update your application to connect to the master node
  4. For managed Redis services, verify you're using the primary endpoint
redis โ€” error
redis-cli -h <your-redis-host> -p <your-redis-port>
> INFO REPLICATION
READONLY You can't write against a read only replica

What this error means

In a Redis replication architecture, the primary master node handles all write operations while replica nodes synchronize data and serve read-only requests. When a write command (SET, DEL, INCR, HSET, etc.) is issued against a replica, Redis immediately rejects it with this READONLY error. This protection ensures that replicas remain exact copies of the master and prevents split-brain scenarios where replicas diverge from the master's state.

Typical symptoms

  • Redis write operations fail with the exact error message 'READONLY You can't write against a read only replica'
  • All write commands (SET, DEL, INCR, LPUSH, HSET, etc.) are rejected
  • Read-only operations (GET, SCAN, HGET, etc.) work correctly
  • Error appears suddenly after cluster failover, node restart, or DNS changes
  • Error occurs intermittently if load balancing routes some requests to replicas

Common causes

  1. Application connection string points to a replica node instead of the master node
  2. Automatic failover promoted a replica to master, but the application still connects to the old master (now a replica)
  3. Load balancer or connection pooling is incorrectly routing write requests to replica nodes
  4. Redis Cluster misconfiguration where client doesn't understand slot-to-master mapping
  5. DNS caching in application or client library stale after topology change
  6. Redis client library's retry logic is retrying failed writes on wrong node
  7. Managed Redis service (AWS ElastiCache, Google Memorystore) configured with read-only endpoint as primary

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

1Check if the node you're connected to is a replica

Connect to your Redis instance and query its replication status:

bash
redis-cli -h <your-redis-host> -p <your-redis-port>
> INFO REPLICATION

Look for the role field in the output:
- If it shows role:master, your node is correct. The error comes from configuration issues.
- If it shows role:slave, you are connected to a replica and must switch to the master.

2Identify the master node address

If you're on a replica, extract the master's address from the replication info:

bash
redis-cli -h <replica-host> -p <replica-port>
> INFO REPLICATION

Find these fields in the output:

bash
master_host:10.0.0.5
master_port:6379

The master_host and master_port values are what your application should connect to.

3Update your application to connect to the master node

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

Node.js (ioredis):

javascript
const redis = require('ioredis');
const client = new redis({
  host: 'master-host-ip',  // NOT replica-host-ip
  port: 6379,
  password: 'your-password',
  retryStrategy: (times) => Math.min(times * 50, 2000)
});

Node.js (redis client):

javascript
const { createClient } = require('redis');
const client = createClient({
  host: 'master-host-ip',
  port: 6379
});

Python (redis-py):

python
import redis
r = redis.Redis(
    host='master-host-ip',
    port=6379,
    password='your-password',
    decode_responses=True
)
# Test with a write
r.set('test-key', 'test-value')

Java (Jedis):

java
Jedis jedis = new Jedis("master-host-ip", 6379);
jedis.set("test-key", "test-value");
4For managed Redis services, verify you're using the primary endpoint

If you're using a cloud provider's managed Redis:

AWS ElastiCache:
1. Go to ElastiCache โ†’ Redis Clusters
2. Select your cluster
3. Under 'Endpoints', use the Primary Endpoint for writes
4. Do NOT use read replicas or reader endpoints
5. Example correct endpoint: my-redis.abc123.ng.0001.use1.cache.amazonaws.com:6379

Google Cloud Memorystore:
1. Open Memorystore for Redis
2. Click your instance
3. Use the Primary Endpoint in your application
4. Replicas are for failover, not client connections

Azure Cache for Redis:
1. Open your cache resource
2. Copy the Primary Connection String
3. Avoid geo-replicas for writes unless your app explicitly handles them

5Use Redis Sentinel for automatic master discovery (recommended for HA)

If running Redis with Sentinel for high availability, let your client discover the master automatically:

Node.js (ioredis with Sentinel):

javascript
const redis = require('ioredis');
const client = new redis.Sentinel([
  { host: 'sentinel-1', port: 26379 },
  { host: 'sentinel-2', port: 26379 },
  { host: 'sentinel-3', port: 26379 }
], {
  name: 'mymaster'  // Service name in sentinel config
});

Python (redis-py with Sentinel):

python
from redis.sentinel import Sentinel
sentinels = [('sentinel-1', 26379), ('sentinel-2', 26379)]
sentinel = Sentinel(sentinels)
master = sentinel.master_for('mymaster', socket_timeout=0.1)
master.set('key', 'value')

Sentinel automatically tracks master/replica topology and updates clients on failover.

6For Redis Cluster, use a cluster-aware client

If using Redis Cluster, ensure your client understands slot mapping:

Node.js (ioredis with Cluster):

javascript
const redis = require('ioredis');
const cluster = new redis.Cluster([
  { host: 'node-1', port: 6379 },
  { host: 'node-2', port: 6379 },
  { host: 'node-3', port: 6379 }
]);
cluster.set('key', 'value');  // Client routes to correct slot master

Python (redis-py with Cluster):

python
from rediscluster import RedisCluster
rc = RedisCluster(
    startup_nodes=[{'host': 'node-1', 'port': 6379}],
    decode_responses=True
)
rc.set('key', 'value')

Cluster-aware clients automatically route write commands to the correct master node for each key's hash slot.

Advanced notes

Replica Read-Only Configuration: The replica-read-only parameter in redis.conf defaults to yes. If set to no, replicas can accept writes, but this is strongly discouraged because it breaks replication consistency. The master's writes will overwrite replica-only changes, causing data loss.

Disabling Replica Read-Only (NOT RECOMMENDED): If you absolutely must write to a replica:

bash
redis-cli -h <replica-host>
> CONFIG SET replica-read-only no

But understand: writes to a replica are lost on failover, and the master's replication stream will overwrite them anyway.

DNS and Client-Side Caching: Some Redis clients cache DNS results or connection objects. After failover or topology changes, stale caches may point to old nodes. Solutions: configure short DNS TTLs, use client libraries with auto-reconnection, or implement application-level health checks.

Failover Scenarios: In production, failover events (master down, Sentinel promoting replica) cause temporary unavailability. Client libraries should:
1. Detect the READONLY error
2. Refresh their node list
3. Retry on the newly promoted master

IORedis and redis-py Sentinel clients handle this automatically.

Cluster vs Replication: Don't confuse Redis Cluster (horizontal scaling) with Redis Replication (HA). In Cluster mode, each slot has a master and replicas; writes must go to the slot's master. In Replication mode, there's one master and N replicas. Both reject writes on replicas by default.

Frequently asked questions

What does "READONLY You can't write against a read only replica" mean?
In a Redis replication architecture, the primary master node handles all write operations while replica nodes synchronize data and serve read-only requests. ) is issued against a replica, Redis immediately rejects it with this READONLY error. This protection ensures that replicas remain exact copies of the master and prevents split-brain scenarios where replicas diverge from the master's state.
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 design to maintain data consistency across the replication cluster.
What causes "READONLY You can't write against a read only replica"?
Application connection string points to a replica node instead of the master node Automatic failover promoted a replica to master, but the application still connects to the old master (now a replica) Load balancer or connection pooling is incorrectly routing write requests to replica nodes
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