Question

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.

Is there a way around this?

Was it helpful?

Solution

When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.

You may also need to make sure your client can handle changed/missing master nodes appropriately.

If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.

OTHER TIPS

Redis Team has very good documentation on this

Core Steps:

  • Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
  • If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
  • Wait for the replication initial synchronization to complete (check the slave log file).
  • Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
  • Configure all your clients in order to use the new instance (that is, the slave).
  • Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.

Full Documentation:

Upgrading or restarting a Redis instance without downtime

You can use Redis Sentinel for doing this, the sentinel will automatically promote a slave as new master. you can find more info here http://redis.io/topics/sentinel.

Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.

Here there will be no downtime or manual configuration of config file is needed. You can visit above link to find out how to configure sentinel for your redis servers.

Note, you may have to check and set the following config to write to your slave. ("Since Redis 2.6 by default slaves are read-only")

redis-cli config set slave-read-only no

-- Example

-bash-4.1$ redis-cli info
 Server
redis_version:2.6.9

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
(error) READONLY You can't write against a read only slave.

-bash-4.1$ redis-cli slaveof no one
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"


-bash-4.1$ redis-cli config set slave-read-only no
OK

-bash-4.1$ redis-cli slaveof admin2.mypersonalsite.com 6379
OK

-bash-4.1$ redis-cli set temp 42
OK

-bash-4.1$ redis-cli get temp
"42"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top