# Redis mac 安装及配置信息
# 安装命令
1 | brew install redis |
# 开启服务
1 | brew services start redis |
# 关闭服务
1 | brew services stop redis |
如果出现提示类似于

执行
1 | brew update |
然后,继续执行上述命令即可
# 指定端口
1 | redis-cli -h localhost -p 6379 |
# 配置文件开启密码
1 | cd /opt/homebrew/etc |
# 如何查找配置文件位置
1 | brew list redis |

找到 plist 文件,cat 命令查看,并找出 conf 配置文件位置即可
1 | cat /opt/homebrew/Cellar/redis/7.2.5/homebrew.mxcl.redis.plist |

# 记得备份配置文件
1 | cp /opt/homebrew/etc/redis.conf /opt/homebrew/etc/redis.conf.backup |
# 修改配置文件
1 | cd /opt/homebrew/etc/ |
设置开启密码

1 | # 允许访问的地址,默认是127.0.0.1,会导致只能在本地访问。修改为0.0.0.0则可以在任意IP访问,生产环境不要设置为0.0.0.0 |
Redis 的其它常见配置:
1 | # 监听的端口 |
# Redis 命令行客户端
Redis 安装完成后就自带了命令行客户端:redis-cli,使用方式如下:
1 | redis-cli [options] [commonds] |
其中常见的 options 有:
-h 127.0.0.1:指定要连接的 redis 节点的 IP 地址,默认是 127.0.0.1-p 6379:指定要连接的 redis 节点的端口,默认是 6379-a 123321:指定 redis 的访问密码
其中的 commonds 就是 Redis 的操作命令,例如:
ping:与 redis 服务端做心跳测试,服务端正常会返回pong
