1. 下载
注:官网下载的需要编译,Github 上面有编译好的可以直接使用
2. Mac
注:这里下载的是官网上的 Redis 4.0.14
2.1 安装
- 把下载的
.tar.gz
文件解压到指定目录 - 打开终端,进入到你自己解压目录的具体路径,如
MacBook-Pro:~ zouwencong$ cd ~/Tools/redis-4.0.14/
- 编译测试:
sudo make test
- 编译安装:
sudo make install
2.2 启动脚本
注:这里就不把Redis
配置到环境变量中了,因为配置后每次启动还是得打开终端输入命令,太麻烦了;所以就写一个启动脚本,每次需要打开时双击一下脚本文件就可以了
- 打开终端
- 进入到桌面:
cd ~/Desktop/
- 新建一个文件:
touch redis-start.sh
- 编辑文件:
vim redis-start.sh
- 输入
i
进入编辑模式,粘贴如下内容(路径更改为你自己的解压目录)
#!/bin/bash
cd /Users/zouwencong/Tools/redis-4.0.14/
src/redis-server redis.conf
- 保存并退出:
esc
+:
+wq
+回车 - 赋值执行权限:
chmod +x redis-start.sh
- 到桌面中,右键刚刚新建的
redis-start.sh
文件 打开方式
->其他...
- 启用:选择
所有应用程序
- 勾选
始终以此方式打开
- 点击
实用工具
- 双击
终端
2.3 停止脚本
- 打开终端
- 进入到桌面:
cd ~/Desktop/
- 新建一个文件:
touch redis-stop.sh
- 编辑文件:
vim redis-stop.sh
- 输入
i
进入编辑模式,粘贴如下内容
#!/bin/bash
## grep redis:包含 redis
## grep -v grep:不包含 grep
## awk '{ print $2 }':输出结果的第二部分内容
##ALL=`ps aux | grep redis`
##echo $ALL
##STR=`ps aux | grep redis | awk '{ print $11 }'`
##echo $STR
PID=`ps aux | grep redis | grep -v grep | grep -v /bin/bash | awk '{ print $2 }'`
echo $PID
kill -9 $PID
- 保存并退出:
esc
+:
+wq
+回车 - 赋值执行权限:
chmod +x redis-stop.sh
- 到桌面中,右键刚刚新建的
redis-stop.sh
文件 打开方式
->其他...
- 启用:选择
所有应用程序
- 勾选
始终以此方式打开
- 点击
实用工具
- 双击
终端
3. Windows
注:这里下载的是 Github 上的 Redis 3.0.504
3.1 安装
- 把下载的
.zip
文件解压到指定目录
3.2 启动脚本
注:这里同样也写一个启动脚本
- 右键新建
文本文档
- 更改文件名为
redis-start.bat
(注意需要显示文件扩展名) - 右键
redis-start.bat
,编辑,粘贴如下内容(路径更改为你自己的解压目录)
@echo off
cd C:\Tools\Redis-x64-3.0.504\
redis-server.exe redis.windows.conf
exit
- 保存,关闭
- 由于 Windows 上的 Redis 是前台启动的,所以关闭窗口即关闭 Redis
4. 其它配置
4.1 redis.conf(Mac)/ redis.windows.conf(Windows)
- 进入到你自己解压目录的具体路径,如
/Users/zouwencong/Tools/redis-4.0.14
C:\\Tools\\Redis-x64-3.0.504
- 使用工具打开
redis.conf
/redis.windows.conf
文件
4.2 设置密码
- 查找字符串:
requirepass foobared
- 在下面添加一行,如设置密码为
123456789
requirepass 123456789
- 保存
4.3 后台启动(Mac)
注:Windows 中不支持后台启动
# On Windows, daemonize and pidfile are not supported.
# However, you can run redis as a Windows service, and specify a logfile.
# The logfile will contain the pid.
- 查找字符串:
daemonize no
- 更改
daemonize no
为daemonize yes
- 保存
4.4 持久化方案
注:Redis
有两种持久化方案,默认为rdb:存取数据速度快
,还有一种为aof:可以保证数据的完整性
- rdb 方案生成的文件为
dump.rdb
- aof 方案生成的文件为
appendonly.aof
- 接下来更改为 aof
- 查找字符串:
appendonly no
- 更改
appendonly no
为appendonly yes
- 如果下面的
appendfilename "appendonly.aof"
被注释了,那么就去掉注释 - 保存
- 这点仅对于 Windows,更改 aof 后,
redis-start.bat
脚本双击后可能会闪退,这时右键appendonly.aof
文件,点击属性
,去掉只读
,应用
,确定
希望能够帮助到你
over