下载、解压、重命名并且编译安装Redis:
~ wget http://download.redis.io/releases/redis-3.2.5.tar.gz
~ tar xzf redis-3.2.5.tar.gz
~ mv redis-3.2.5 redis
~ cd redis
~ make
~ make test
~ make install
注意:
make test 可能遇到问题:
Test replication partial resync: ok psync (diskless: yes, reconnect: 1) in tests/integration/replication-psync.tcl Expected condition '[s -1 sync_partial_ok] > 0' to be true ([s -1 sync_partial_ok] > 0)
解决方案:
■ 解决办法:
1,只用单核运行 make test:
taskset -c 1 sudo make test
2,更改 tests/integration/replication-psync.tcl 文件:
vi tests/integration/replication-psync.tcl
把对应报错的那段代码中的 after后面的数字,从100改成 500。我个人觉得,这个参数貌似是等待的毫秒数。
if($reconnect){
for{set j 0}{$j < $duration*10} {incr j}{
after 100
}
}
配置文件redis.conf
redis解压目录里有一个配置文件redis.conf ,编辑此配置文件,找到 dir ./ 这一行。redis会将内存中的数据写入文件中,而此配置就是指定数据文件保存的路径。我本机指定的目录为:
dir /Users/jackiehff/Software/redis_data/
编辑过后,将配置文件移动到 /usr/local/etc 目录下
~ sudo mv redis.conf /usr/local/etc
启动Redis
终端输入:
~ /usr/local/bin/redis-server /usr/local/etc/redis.conf
测试连通性 :
~ cd /usr/local/bin
~ ./redis-cli
127.0.0.1:6379> set name hi
OK
127.0.0.1:6379> get name
"hi"
设置开机自动启动redis server
新建plist文件:
sudo vi /Library/LaunchDaemons/io.redis.redis-server.plist
文件内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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/etc/redis.conf</string>
</array>
<key>RunAtLoad</key><true/> </dict>
</plist>
使用launchctl设置开机自动启动:
sudo launchctl load /Library/LaunchDaemons/io.redis.redis-server.plist
使用launchctl启动redis server
sudo launchctl start io.redis.redis-server
使用launchctl停止redis server
sudo launchctl stop io.redis.redis-server
redis 3.2.5 on MAC
最新推荐文章于 2024-06-15 17:30:46 发布