Redis readonly you cant write against a read only replica

sentinel cluster and redis on it, when there is change to the master, this issue happen, you cannot solve it 100%, On practice, you need to ensure that redis client is able to tolerate the failure, work on safe mode, on certain exceptions it may retry few attempts before giving up or make it up. To know who is master, ask sentinel, to check master readyness, use HA proxy, https://www.haproxy.com/blog/haproxy-advanced-redis-health-check/

If the above error occurs, it means that the current redis service is read-only and has no write permission. It is estimated that the service is used as a slave database.

solution:

  • Open the configuration file corresponding to the redis service and modify the value of the attribute slave-read-only to no, so that it can be written.
  • Or a faster way is through

    redis-cli

    Command to open the client mode, enter

    slaveof no one

    Command to stop the current redis service from receiving synchronization from other redis services, and at the same time upgrade itself to the main database.

Because the master-slave replication cluster was configured before, the configuration was changed disorderly

There are two solutions:

1. Open the configuration file corresponding to the redis service, and change the value of the attribute slave read-only to no, so that it can be written.

2. Open the client mode through the redis cli command, and enter the slave of no one command

Read More:

Ankit Gupta

unread,

Dec 14, 2021, 6:37:45 AM12/14/21

to Redis DB

Hi Experts,

We are using redis version 5.x, and using sentinel based architecture.

Below is the setup

N1(M)

/         \

/             \

N2(S)         N3(S)

N1 got crashed  , and due to failover N3 was promoted as a new master. After sometime when N1 was recovered & joined the setup/cluster as slave it requested for a full re-synchronization from N3(present master) due to which BGSave was invoked. 

During this process any request on master , was giving below error:

org.springframework.data.redis.connection.RedisPipelineException: Pipeline contained one or more invalid commands; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: READONLY You can't write against a read only replica.; nested exception is redis.clients.jedis.exceptions.JedisDataException: READONLY You can't write against a read only replica.

We have few queries around this

1. Are we getting this error because master was busy in serving any other request?

2. Is there a configuration we can do so that if another slave is already connected then new node should do sync from existing slave?

3. Is this the expected behaviour?

Thanks in advance.

-Ankit

Vivek Mishra

unread,

Jul 22, 2022, 1:13:25 PMJul 22

to Redis DB


In my case i set REDIS_HOST to the service redis-headless and it worked

Ankit Gupta

unread,

Aug 28, 2022, 7:46:54 AMAug 28

to Redis DB

Hi All,

We received this error again in our production setup.  Surprisingly there's nothing revealed in the redis.log or even in sentinel.log.  

If someone has someone faced similar issue, then you're help on this much appreciated.

Ankit Gupta

unread,

Aug 28, 2022, 7:48:00 AMAug 28

to Redis DB

Hi Vivek,

Has the issue resolved after this fix ?

Can you please share the steps that you followed for this ?

On Saturday, July 23, 2022 at 1:43:25 AM UTC+5:30 Vivek Mishra wrote:

Ankit Gupta

unread,

Sep 4, 2022, 10:19:59 PMSep 4

to Redis DB

Hi Team,

Has anyone faced such an issue. Can this be an issue with # of connections or sentinel overload or client library ?

  1. Home
  2. Commands
  3. READONLY

Syntax

READONLY
Available since:3.0.0Time complexity:O(1)ACL categories: @fast, @connection,

Enables read queries for a connection to a Redis Cluster replica node.

Normally replica nodes will redirect clients to the authoritative master for the hash slot involved in a given command, however clients can use replicas in order to scale reads using the READONLY command.

READONLY tells a Redis Cluster replica node that the client is willing to read possibly stale data and is not interested in running write queries.

When the connection is in readonly mode, the cluster will send a redirection to the client only if the operation involves keys not served by the replica's master node. This may happen because:

  1. The client sent a command about hash slots never served by the master of this replica.
  2. The cluster was reconfigured (for example resharded) and the replica is no longer able to serve commands for a given hash slot.

Return

Simple string reply

Feedback

If you've found issues on this page, or have suggestions for improvement, please submit a request to merge or open an issue in the repository.