Redis在Mac Mavericks上的环境设置
使用Homebrew进行安装。
因为我想在Mac开机时自动启动,所以我会使用launchctl进行设置。
请参考以下链接:http://qiita.com/checkpoint/items/58b9b0193c0c46400eeb
$ brew install redis
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/redis-2.8.8.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring redis-2.8.8.mavericks.bottle.tar.gz
==> Caveats
To have launchd start redis at login:
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
Then to load redis now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Or, if you don't want/need launchctl, you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
? /usr/local/Cellar/redis/2.8.8: 10 files, 1.3M
$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
我相信大多数人只要做到这一步就可以无错误地启动。
但是对我来说,发生了错误。
因为无法顺利启动,所以我要调查一下原因。
$ redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
$ redis-server /usr/local/etc/redis.conf
*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 369
>>> 'vm-enabled no'
Bad directive or wrong number of arguments
当查看/usr/local/Cellar/redis/时,发现早些时候安装的版本2.4.6仍在其中。
看了一下设置文件,时间戳大约是在2012年左右。
根据上述错误看,我觉得当启动新安装的2.8.8版本时,它似乎直接读取了2.4.6版本的设置文件。
因此,我先卸载了全部的Redis,然后删除了配置文件(/usr/local/etc/redis.conf、/usr/local/etc/redis-sentinel.conf),再重新安装了Redis。
$ brew remove redis
Uninstalling /usr/local/Cellar/redis/2.8.8...
$ brew remove redis
Uninstalling /usr/local/Cellar/redis/2.4.6...
$ rm /usr/local/etc/redis.conf /usr/local/etc/redis-sentinel.conf
$ brew install redis
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/redis-2.8.8.mavericks.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/redis-2.8.8.mavericks.bottle.tar.gz
==> Pouring redis-2.8.8.mavericks.bottle.tar.gz
==> Caveats
To reload redis after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
==> Summary
? /usr/local/Cellar/redis/2.8.8: 10 files, 1.3M
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
在我做到这一步并在命令行上确认了行为后,它成功地运行了。
$ redis-cli
127.0.0.1:6379> set keyfuga fugafuga
OK
127.0.0.1:6379> get keyfuga
"fugafuga"
127.0.0.1:6379> keys *
1) "keyfuga"