MacOS 安装Redis并设置密码

在开发过程中,需要本地进行安装Redis进行测试,记录了下MacOS环境下安装Redis,以及设置密码。

Brew 安装

sh 复制代码
$ brew install redis

启动服务

sh 复制代码
# 启动服务
brew services start redis
# 关闭服务
brew services stop redis
# 重启服务
brew services restart redis

# 查看 redis 服务进程
ps axu | grep redis

# redis默认端口号6379,默认 auth 为空,输入以下命令即可连接
redis-cli -h 127.0.0.1 -p 6379

设置密码

方式一:设置临时密码

重启服务后密码会失效

sh 复制代码
$ config set requirepass 123456
方式二:设置永久密码

需要修改配置 redis.conf

sh 复制代码
# 查看 brew 安装 redis 的配置文件地址
$ brew list redis
/opt/homebrew/Cellar/redis/7.0.11/.bottle/etc/ (2 files)
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-benchmark
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-check-aof
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-check-rdb
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-cli
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-sentinel
/opt/homebrew/Cellar/redis/7.0.11/bin/redis-server
/opt/homebrew/Cellar/redis/7.0.11/homebrew.mxcl.redis.plist
/opt/homebrew/Cellar/redis/7.0.11/homebrew.redis.service

# 进入目录
$ cd /opt/homebrew/Cellar/redis/7.0.11

# 查看 redis 配置文件位置
$ cat  homebrew.mxcl.redis.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
...
	<array>
		<string>/opt/homebrew/opt/redis/bin/redis-server</string>
		<string>/opt/homebrew/etc/redis.conf</string>
	</array>
...
</plist>

# 编辑 /opt/homebrew/etc/redis.conf
$ vim /opt/homebrew/etc/redis.conf

# 查找 「#requirepass foobared」 进行修改
requirepass 123456

# 重启 redis 服务
$ brew services restart redis
查询密码:
sh 复制代码
# 查询密码
$ config get requirepass

# 验证密码
127.0.0.1:6379> auth 123456
相关推荐
咖丨喱37 分钟前
【Action帧简要分析】
服务器·数据库·asp.net
没饭吃!38 分钟前
NHibernate案例
数据库·hibernate
泷羽Sec-静安1 小时前
OSCP官方靶场-Solstice WP
服务器·网络·数据库
路先生的杂货铺1 小时前
mac m1芯片 安装pd及win10系统
macos
goodmao1 小时前
【macOS】【Swift】【RTF】黑色文字在macOS深色外观下看不清的解决方法
macos
IvanCodes1 小时前
Oracle 视图
大数据·数据库·sql·oracle
德育处主任Pro2 小时前
「py数据分析」04如何将 Python 爬取的数据保存为 CSV 文件
数据库·python·数据分析
都叫我大帅哥2 小时前
🔥 Redis缓存击穿:从“崩溃现场”到“高并发防弹衣”的终极指南
redis
许白掰2 小时前
Linux入门篇学习——Linux 编写第一个自己的命令
linux·运维·数据库·嵌入式硬件·学习
打不了嗝 ᥬ᭄2 小时前
文件系统----底层架构
linux·运维·数据库