1. 程式人生 > 其它 >Redis.conf詳解

Redis.conf詳解

Redis.conf詳解

啟動的時候,就通過配置檔案來啟動!

單位

配置檔案unit單位 對大小寫不敏感!

包含

就是好比我們學習Spring、Import,include一般

網路

bind 127.0.0.1    # 繫結的ip
protected-mode yes     # 保護模式
port 6379    # 埠設定

通用GENERAL

daemonize yes    # 以守護程序的方式執行,預設是no,我們需要自己開啟為yes!
pidfile /var/run/redis_6379.pid    # 如果以後臺的方式執行,我們就需要指定一個pid檔案!
# 日誌
# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
# verbose (many rarely useful info, but not a mess like the debug level)
# notice (moderately verbose, what you want in production probably)    生產環境
# warning (only very important / critical messages are logged)
loglevel notice
logfile "" # 日誌檔案位置
databases 16    # 預設資料庫個數 16個
always-show-logo yes    # 是否總是顯示logo

快照

持久化,在規定的時間內,執行了多少次操作,則會持久化到檔案.rdb.aof

redis是記憶體資料庫,如果沒有持久化,那麼資料斷電及失!

# 如果900s內,如果至少有1個key進行了修改,我們就進行持久化操作
save 900 1
# 如果300s內,如果至少有10個key進行了修改,我們就進行持久化操作
save 300 10
# 如果60s內,如果至少有10000個key進行了修改,我們就進行持久化操作
save 60 10000
stop-writes-on-bgsave-error yes    # 持久化如果出錯,是否還要繼續工作!
rdbcompression yes    # 是否壓縮 rdb 檔案,需要消耗一些cpu資源!
rdbchecksum yes    # 儲存rdb檔案的時候,進行錯誤的檢查校驗!
dir ./    # rdb 檔案儲存的目錄!

REPLICATION複製,後面再講解主從複製

SECURITY 安全

可以在這裡設定redis的密碼,預設是沒有密碼!

127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass "123456"
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "123456"

限制CLIENTS

# maxclients 10000    設定能連線上redis的最大客戶端的數量
# maxmemory <bytes>    redis 配置最大的記憶體容量
# maxmemory-policy noeviction    記憶體達到上限之後的處理策略
1、volatile-lru:只對設定了過期時間的key進行LRU(預設值) 
2、allkeys-lru : 刪除lru演算法的key   
3、volatile-random:隨機刪除即將過期key   
4、allkeys-random:隨機刪除   
5、volatile-ttl : 刪除即將過期的   
6、noeviction : 永不過期,返回錯誤

APPEND ONLY MODE aof配置

appendonly no    # 預設是不開啟aof模式的,預設是使用rdb方式持久化的,在大部分所有的情況下,rdb完全夠用!
appendfilename "appendonly.aof"    # 持久化的檔案的名字
# appendfsync always    # 每次修改都會 sync,消耗效能
appendfsync everysec    # 每秒執行一次 sync,可能會丟失這1s的資料
# appendfsync no    # 不執行 sync ,這個時候作業系統自己同步資料,速度最快!