When it is not set to boot automatically, the following command will be executed every time:
redis-server /usr/local/redis-5.0.5/redis.conf
Let's start to set up redis to start automatically
You need a .plist file to specify which programs to start on boot. First let's create a .plist file:
sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
Here is an example of a .plist configuration file for booting:
<?xml version="1.0" encoding="UTF-8"?>
<!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>io.redis.redis-server</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/redis/bin/redis-server</string>
<string>//usr/local/etc/redis.conf</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
After editing the plist file, we need to load the file into launchd and use the launchctl command. The specific command is as follows:
sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
After restarting, redis can be booted and started. If you don't want to restart, you can also use the following command:
sudo launchctl start io.redis.redis-server
If you want to close redis, use the following command:
sudo launchctl stop io.redis.redis-server
For ease of use, we can set aliases for redis on and off commands:
alias redisstart='sudo launchctl start io.redis.redis-server'
alias redisstop='sudo launchctl stop io.redis.redis-server'