I don’t like to remember to do stuff, because I invariably forget. I’ve recently started using Redis for a couple of projects and so I had to install it on my Mac for development. Here’s what I did to make Redis start on boot.
I didn’t use homebrew to install Redis, I compiled version 3.2.0 from the source. It’s actually super easy. It’s just “make,” “make test” and then “sudo make install.” Doing so installs Redis in /usr/local/bin.
Compiling from source doesn’t get you a redis.conf file, but I just used the default example I found on Redis.io. I saved it in /usr/local/etc. If you’ve installed things in a different location, adjust the following instructions to match your Redis setup.
To make Redis automagically startup on boot, I’m using launchd.
Create a simple xml document in /Library/LaunchDaemons.
sudo vim /Library/LaunchDaemons/redis-server.plist
In redis-server.plist put this.
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>redis-server</string> <key>ProgramArguments</key> <array> <string>/usr/local/bin/redis-server</string> <string>/usr/local/etc/redis.conf</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
To repeat, if you don’t have redis-server installed in /usr/local/bin, you need to change your path in the xml file. Also, if you don’t use a redis.conf, or it’s not installed in /usr/local/etc, update accordingly. If you don’t have a redis.conf, you can just remove it from this xml file.
Now load the redis.server.plist into launchd.
sudo launchctl load /Library/LaunchDaemons/redis-server.plist
You only have to do this once, now you should have control of your redis server via launchd.
Fire up Redis with this command.
sudo launchctl start redis-server
If you did it correctly, crank up the redis-cli client and type “ping.” You should connect and receive a “PONG” response. If you didn’t, go to /usr/local/bin and try running “sudo ./redis-server.” It should start up. If it doesn’t, fix whatever error is being generated. If it did work, now try it with the redis.conf file: “sudo ./redis-server ../etc/redis.conf.” If this doesn’t start Redis, fix any errors reported. If it does start, run redis-cli again and try the “ping” test.