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
相关推荐
csdn_aspnet4 分钟前
如何在 Mac、Ubuntu、CentOS、Windows 上安装 MySQL 客户端
linux·windows·mysql·macos·centos
我的golang之路果然有问题9 分钟前
mac M系列芯片 unity 安装会遇到的错误以及解决
经验分享·学习·macos·unity·游戏引擎
qq_54702617911 分钟前
Canal实时同步MySQL数据到Elasticsearch
数据库·mysql·elasticsearch
java1234_小锋1 小时前
REDIS集群会有写操作丢失吗?为什么
数据库·redis·缓存
兰若姐姐1 小时前
如何进行MSSQL提权?sp_oacreate、sp_oamethod和沙盒提权以及xp_regwrighte提权
数据库·sqlserver
一抓掉一大把1 小时前
秒杀-订单创建消费者CreateOrderConsumer
网络·数据库
心灵宝贝3 小时前
如何安装 PDF Reader Pro for Mac v3.2.1.0?超简单DMG安装步骤(附安装包)
macos
一只小bit3 小时前
MySQL事务:如何保证ACID?MVCC到底如何工作?
数据库·mysql·oracle
小猪咪piggy4 小时前
【项目】小型支付商城 MVC/DDD
java·jvm·数据库
向阳而生,一路生花4 小时前
redis离线安装
java·数据库·redis