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
相关推荐
GDAL4 分钟前
BoltDB vs Redis 读性能对比:实测表现与原理差异
redis·boltdb
Fortune7925 分钟前
用Pandas处理时间序列数据(Time Series)
jvm·数据库·python
2401_8785302130 分钟前
高级爬虫技巧:处理JavaScript渲染(Selenium)
jvm·数据库·python
Sephiroth.Ma31 分钟前
Mac 提示“Docker 已损坏,无法打开”?我这样排查后 10 分钟修好
macos·docker·容器
2401_8735449234 分钟前
使用Black自动格式化你的Python代码
jvm·数据库·python
艾莉丝努力练剑34 分钟前
【MYSQL】MYSQL学习的一大重点:表的约束
linux·运维·服务器·开发语言·数据库·学习·mysql
Fortune7936 分钟前
用Python破解简单的替换密码
jvm·数据库·python
量子炒饭大师1 小时前
【OpenClaw修炼宝典】—— 【macOS安装篇】想玩《爪子船长》复刻版却卡在安装?OpenClaw 从零环境搭建与编译全攻略 (小白避坑指南)
macos·openclaw·小龙虾·龙虾
2401_873544921 小时前
Python深度学习入门:TensorFlow 2.0/Keras实战
jvm·数据库·python
会编程的土豆1 小时前
全面解析数据库锁机制:从行锁到死锁的深度剖析
数据库