1 創(chuàng)建.plist配置文件
為了讓 Redis 在啟動時自動啟動,我使用的是 launchd。在 /Library/LaunchDaemons 中創(chuàng)建一個簡單的xml文檔。
sudo vim /Library/LaunchDaemons/redis-server.plist
注意:
- 先執(zhí)行
which redis-server查看redis的安裝位置; - 再執(zhí)行
sudo find / -name redis.conf查看reids.conf的位置。
然后正確填寫以下代碼:
<!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>
如果您沒有 redis.conf ,則只需將其從此xml文件中刪除即可。
2 將 redis.server.plist 加載到 launchd 中
sudo launchctl load /Library/LaunchDaemons/redis-server.plist
此時 Mac 開機(jī)或重啟都會自動啟動 redis