Redis reload configuration changes without restarting service

When I change redis configuration via puppet, is there a better way to load the configuration other than restarting the redis service?


Yes you could do it, but it'll involve writing your own customer provider within Puppet. It's non trivial, but if you were willing to reduce the settings you cared about it would be simpler.

A simple case might be only setting master or slave dynamically. We'd make those parameters to your Redis class. We'd template the redis.conf of course and put these settings in it same as you're likely doing now. Then you'd need some sort of syntax like the following through the semantics should probably be more expressive.

redisconf { 'master': enable => 'true', } 

redisconf would be your custom provider that would be written in Ruby. It'll need to connect to the port of the Redis server (which is another input and default you'd need to set). Once you connect you'd need to issue an info and grab the resulting output as a hash.

First step is to determine what version of Redis you have. If it's 2.4/2.6 you can use config set and config get, else you'll use the hash we already have and run commands manually. In our example you'd check the value of role. If it's master, do nothing. If it's a slave then execute 'slaveof no one' and generate a Puppet event. Assuming there are differences the redisconf Puppet provider would need make changes and ideally verify or throw and error. Wrap the whole thing in Puppet-isms and you'd be set.

It would be a nice little project if you decided to take it on.


As long as you have persistence set up via a save directive, restarts are (mostly) non-destructive.

If the redis process does not have persistence, you can turn it on with CONFIG SET

telnet 127.0.0.1 1234
CONFIG SET SAVE "900 1 300 10 60 10000"

Check that the data backup is created by going to the directory specified by the dir config value and looking for a file that equals the dbfilename config value. Once that's created, you can edit config and restart redis and you'll see something like this in the log:

[17296] 18 Nov 00:38:32.253 * DB loaded from disk: 0.158 seconds

Viola, you've restarted redis and kept most of your data, I excluding what happened between the backup file creation and the restart.