1. 程式人生 > 實用技巧 >Redis-08-配置檔案部分詳解

Redis-08-配置檔案部分詳解

單位,大小寫不敏感
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes

檔案包含
# include .\path\to\local.conf
# include c:\path\to\other.conf

保護模式,預設開啟
protected-mode yes

埠號
port 6379

tcp-backlog 511

繫結ip地址
# bind 192.168.1.100 10.0.0.1
bind 127.0.0.1

timeout 0

tcp-keepalive 0

是否開啟守護程序,預設為no
daemonize yes

管理守護程序,預設為no
supervised no

如果以後臺方式,也就是守護程序方式執行,需要一個pid檔案
pidfile /var/run/redis_6379.pid

日誌級別
# 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 ""

syslog-enabled yes

syslog-ident redis

資料庫數量
databases 16

是否顯示log,預設顯示
always-show-log yes

快照
900秒內至少更新1個key,進行持久化操作
save 900 1
300秒內至少更新10個key,進行持久化操作
save 300 10
60秒內至少更新10000個key,進行持久化操作
save 60 10000

持久化如果出錯,是否還需要繼續工作,預設yes
stop-writes-on-bgsave-error yes

是否壓縮rdb檔案,預設yes,需要消耗一些cpu資源
rdbcompression yes

儲存rdb檔案時,進行錯誤校驗
rdbchecksum yes


dbfilename dump.rdb

rdb檔案儲存目錄
dir ./

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

設定redis密碼
# requirepass foobared

限制最大客戶端連線數為10000
# maxclients 10000

最大記憶體容量
maxmemory 500mb

記憶體達到上限的處理策略
# maxmemory-policy noeviction
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations

預設不開啟AOF模式
appendonly no

持久化檔案的名字
appendfilename "appendonly.aof"

# appendfsync always 每次修改都sync,消耗效能
appendfsync everysec 每秒執行一次sync,可能會丟失1秒的資料
# appendfsync no 不執行sync,作業系統自己執行資料同步,速度最快

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

#預設的aof檔案大小,如果aof檔案大於64mb,redis會fork一個新的程序對aof檔案進行重寫
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

notify-keyspace-events ""

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512
list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128
zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes