下载、解压、重命名并且编译安装Redis
~ wget http://download.redis.io/releases/redis-3.0.5.tar.gz
~ tar xzf redis-3.0.5.tar.gz
~ mv redis-3.0.5 redis
~ cd redis
~ make
~ make test
~ make install
配置文件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 jackiehff hi
OK
127.0.0.1:6379> get jackiehff
"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
时间: 2024-10-03 14:02:06