Redis "READONLY You can't write against a read only replica" in CI
The Redis node serving the connection is a replica, and replicas reject writes by default with "READONLY". In CI this happens when the service or compose stack starts a replica (or a cluster) and the client writes to the wrong node.
What this error means
Read commands work but any write fails with "READONLY You can't write against a read only replica.".
(error) READONLY You can't write against a read only replica.Common causes
The client is connected to a replica node
A replica is configured with replica-read-only yes (the default) and rejects writes. The client should target the primary.
A cluster setup routed the write to the wrong node
In a Redis Cluster test stack, a non-owning or replica node returns READONLY for writes that should go to the slot owner or primary.
How to fix it
Connect to the primary node
Point the test client at the primary instance rather than a replica.
env:
REDIS_URL: redis://127.0.0.1:6379/0 # primary, not the replica portRun a single standalone Redis for tests
Most CI suites do not need replication. A single standalone Redis avoids replica routing entirely.
services:
redis:
image: redis:7
ports: ['6379:6379']
options: --health-cmd "redis-cli ping"How to prevent it
- Use a single standalone Redis for tests unless replication is under test.
- Send writes to the primary; use replicas only for reads.
- For a cluster, route writes by the slot owner, not a fixed node.