redis.conf详解之include

2021-11-13  本文已影响0人  小易哥学呀学

1、用法:

在 $yourPath/redis.conf 文件中添加以下配置

include /path/to/local.conf

2、用途:

模块化配置,比如所有服务都有公共的配置,每个服务还需要个性配置,可以抽离出公共配置和个性配置,在公共配置中include个性配置。

3、注意事项:

(1)对同一个配置的多次设置,总是取最后配置的值。

$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 

结果:

/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的值不会被CONFIG REWRITE重写
#step1 启动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"

#参数已经生效,但是配置文件中的值不会被重写。

#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
上一篇 下一篇

猜你喜欢

热点阅读