低代碼開發(fā)平臺(tái) 開源文大俠seo博客
在開發(fā)過程中,需要本地進(jìn)行安裝Redis進(jìn)行測試,記錄了下MacOS環(huán)境下安裝Redis,以及設(shè)置密碼。
Brew 安裝
$ brew install redis
啟動(dòng)服務(wù)
# 啟動(dòng)服務(wù)
brew services start redis
# 關(guān)閉服務(wù)
brew services stop redis
# 重啟服務(wù)
brew services restart redis# 查看 redis 服務(wù)進(jìn)程
ps axu | grep redis# redis默認(rèn)端口號(hào)6379,默認(rèn) auth 為空,輸入以下命令即可連接
redis-cli -h 127.0.0.1 -p 6379
設(shè)置密碼
方式一:設(shè)置臨時(shí)密碼
重啟服務(wù)后密碼會(huì)失效
$ config set requirepass 123456
方式二:設(shè)置永久密碼
需要修改配置 redis.conf
# 查看 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# 進(jìn)入目錄
$ 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」 進(jìn)行修改
requirepass 123456# 重啟 redis 服務(wù)
$ brew services restart redis
查詢密碼:
# 查詢密碼
$ config get requirepass# 驗(yàn)證密碼
127.0.0.1:6379> auth 123456