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
相关推荐
wefg111 分钟前
【Redis】初识 Redis
数据库·redis·缓存
周之瑞2 小时前
技术手记|Redis 与数据库事务不在一个世界:afterCommit、显式补偿还是 Canal?
redis
hacker_LeeFei2 小时前
Windows 下配置 Redis 8.10.2 开机自启:一次踩坑全记录
数据库·windows·redis
传奇开心果编程3 小时前
【SwiftUI入门练中学】第7课 动画与手势:让界面更灵动
学习·macos·ui·ios·swiftui·swift
这个DBA有点耶3 小时前
MySQL字符集与排序规则深入:索引失效的隐蔽场景与排查方法
数据库·mysql·代码规范
zl_dfq3 小时前
Redis 之 【持久化 与 事务】
数据库·redis
闲云自留地4 小时前
从下载到登录:MySQL 在两大系统上的完整安装教程
数据库·mysql
SelectDB技术团队4 小时前
Apache Doris 高性能 Open Lake Variant 读写技术解析(含对比数据)
数据结构·数据库·clickhouse·日志·apache doris·selectdb·湖仓架构升级
一 乐4 小时前
博客管理系统|基于springboot + vue博客管理系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·毕设
茉莉玫瑰花茶5 小时前
GO [ 类型 ]
开发语言·数据库·golang