1、用法:
在 $yourPath/redis.conf 文件中添加以下配置
include /path/to/local.conf
2、用途:
模塊化配置未妹,比如所有服務(wù)都有公共的配置部凑,每個(gè)服務(wù)還需要個(gè)性配置,可以抽離出公共配置和個(gè)性配置,在公共配置中include個(gè)性配置。
3、注意事項(xiàng):
(1)對(duì)同一個(gè)配置的多次設(shè)置埂软,總是取最后配置的值。
$yourPath需要替換為你自己的路徑
/users/xiaoyi $ cat $yourPath/gexing-tcp-keepalive-400.conf
tcp-keepalive 400
/users/xiaoyi $ cat $yourPath/gexing-tcp-keepalive-500.conf
tcp-keepalive 500
/users/xiaoyi $ cat $yourPath/redis.conf | grep "tcp-keepalive"
include $yourPath/gexing-tcp-keepalive-500.conf
tcp-keepalive 300
include $yourPath/gexing-tcp-keepalive-400.conf
結(jié)果:
/users/xiaoyi $ /usr/bin/redis-server $yourPath/redis.conf
/users/xiaoyi $ redis-cli
127.0.0.1:6379> config get tcp-keepalive
1) "tcp-keepalive"
2) "400"
127.0.0.1:6379>
(2)配置文件中include的值不會(huì)被CONFIG REWRITE重寫
#step1 啟動(dòng)redis
/users/xiaoyi $ /usr/bin/redis-server $yourPath/redis.conf
#step2
/users/xiaoyi $ redis-cli
127.0.0.1:6379> config get tcp-keepalive
1) "tcp-keepalive"
2) "400"
127.0.0.1:6379> config set tcp-keepalive 600
OK
127.0.0.1:6379> config get tcp-keepalive
1) "tcp-keepalive"
2) "600"
#參數(shù)已經(jīng)生效纫事,但是配置文件中的值不會(huì)被重寫勘畔。
#step3
/users/xiaoyi $ cat $youPath/redis.conf | grep tcp-keepalive
include $youPath/gexing-tcp-keepalive-500.conf
tcp-keepalive 300
include $youPath/gexing-tcp-keepalive-400.conf
4、原生注釋
# Include one or more other config files here. This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings. Include files can include
# other files, so use this wisely.
#
# Note that option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf