Search code examples
databaserediscopyreplicationmaster-slave

Can you insert data into a Redis replica? Why or why not?


I have a redis-server instance that is a replica of a primary redis-server instance. Also I have a python3 script that uses the redis library to query the replica instance.

However, this script also tries to inserts data using SET. I'm not sure if it successfully inserts or not.

What happens when you use SET on a replica? My understanding is that a replica is supposed to replicate the data of the redis-server instance, so I can only imagine three possible behaviors

  1. Does it pass your SET command up to the primary redis-server instance?
  2. Does it keep your data but only locally?
  3. Does it just ignore your SET command?

I can't find any documentation on this question, and it seems like all three behaviors would be reasonable. If you know what the behavior is, can you please explain why that is the case as opposed to the other two cases?


Solution

  • Does it pass your SET command up to the primary redis-server instance?

    NO

    Does it keep your data but only locally?

    It depends.

    • If your replica is configured to be replica-read-only yes, it will accept write operation, and keep the data locally. However, when syncing with master, master's copy will overwrite it.
    • If your replica is configured to be replica-read-only no, it will refuse write operation.

    Does it just ignore your SET command?

    NO. It either accepts it or refuses it and returns an error reply.