一,创建.plist文件
sudo vim /Library/LaunchDaemons/io.redis.redis-server.plist
添加配置文件
/usr/local/redis-6.0.9/redis.conf 对应你自己的安装目录
<?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/bin/redis-server</string> <string>/usr/local/redis-6.0.9/redis.conf</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist>
二,将文件载入到launchd里
sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
启动命令
sudo launchctl start io.redis.redis-server
关闭命令
sudo launchctl stop io.redis.redis-server
设置别名:
alias redisstart='sudo launchctl start io.redis.redis-server' alias redisstop='sudo launchctl stop io.redis.redis-server'