數據庫的只讀模式,對於在系統出現重大故障,但是又不影響用戶的查詢操作還是很重要的
對於redis 設置只讀模式需要分不同的場景
- master-slave
- cluster
- single
master-slave 模式
這個就比較簡單的了,可以使用哨兵自動解決,或者通過命令行
slaveof host port 命令
cluster 模式
集群模式當前包含了readonly
,readwrite
,我們直接可以通過命令解決
單機模式
原理實際上很簡單,slaveof 設置為自身,然后就只讀了,因為slave 默認就是只讀的
- 操作
slaveof 127.0.0.1 6379
解除readonly 模式
slaveof no one
說明
通過redis.conf 配置文件也是可以的
參考資料
https://redis.io/commands/readonly
https://redis.io/commands/slaveof