skip to Main Content

I want to mark a standalone Redis server (not a Redis-Cluster, not a Redis-Sentinel) as read-only. I have been googling for this for quite sometime but I don’t seem to find a definite answer (Almost all answers point to Clustering or Sentinel). I was looking out for some config modification (CONFIG SET something).

NOTE: config set replica-read-only yes does not make the current redis-server read-only, but only its replicas.

My use-case basically is I am doing a migration wherein at some point I want to make the redis-server read-only. My application code can handle failures whenever a write call happens so that’s not an issue.

Also, if this is not directly possible from redis server, is there something that I can do in the client code that’ll have the same effect (I am using redis-py as the client library)? (Although this is less than ideal)

Things that I’ve tried

  • Played around with config set replica-read-only yes and other configs. They don’t seem to be applying the current redis-server.
  • Tried marking a redis-server as a replica of itself (This was illogical, but just wanted to see if this worked), but turns out it deleted all keys in my local redis, so not something I can do.

2

Answers


  1. There’re several solution you can try:

    • You can use the rename-command config to disable write commands. If you only want to disable small number of commands, that’s a good solution. However, since there’re too many write commands, you might need to have too many configuration, and easy to miss some of them.

    • If you’re using Redis 6.0, you can use Redis ACL to disable write commands for specific users.

    • You can setup a read-only Redis replica for your master, and ask clients to read from the replica.

    Login or Signup to reply.
  2. Once the writes are done and you want to switch the node to read-only, couple of ways to do that:

    1. Modify the redis.conf to have "min-replicas-to-write 3". Since you don’t have 3 replicas your node will stop accepting writes but will continue to serve reads, as shown below:

    enter image description here

    However, please note that after modifying redis.conf, you will have to restart your redis node for the changes to take effect.

    1. Another way is when you want to switch to readonly mode, at that time you create a replica and let it sync with the master and then kill the master node. Then replica will exist as read only.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search