Detailed explanation of Redis.conf basic configuration

  When Redis is started, it is started by formulating a certain configuration file. In actual applications, we can write multiple configurations to start. Let’s share the basic configuration of Redis today.

INCLUDES contains

# 引用其他的配置文件,将多个配置文件组合成一个
include /path/to/local.conf
include /path/to/other.conf

NETWORK

# 绑定主机的IP,如果需要远程访问,可以加*号通配,或者直接绑定公网IP,或者注释掉
bind 127.0.0.1
# 保护默认,默认开启,建议开启
protected-mode yes
# 端口设置,默认6379,在集群时需要修改
port 6379

General configuration

# 守护进程,后台运行,默认为no,需要自己开启
daemonize yes
# 如果是后台运行,就需要指定pid文件
pidfile /var/run/redis_6379.pid
# 日志级别,debug、verbose、notice、warning
loglevel notice
# 日志的文件名
logfile ""
# 默认数据库的数量
databases 16
# 是否显示启动时的logo
always-show-logo yes

SNAPSHOTTING snapshot

# 持久化操作,持久化规则
# 900秒内如果至少有一个key进行了修改,就进行持久化操作
save 900 1
# 300秒内有10个key进修了修改,就进行持久化操作
save 300 10
# 600秒内有10000个key进修了修改,就进行持久化操作
save 60 10000
# 持久化失败了是否继续工作,默认继续工作
stop-writes-on-bgsave-error yes
# 是否压缩rdb文件,需要消耗CPU资源
rdbcompression yes
# 保存rdb文件时进行错误的检验
rdbchecksum yes
# 持久化的文件名
dbfilename dump.rdb
# rdb文件保存的路径,默认在当前路径
dir ./

SECURITY

# 设置密码,默认是没有密码的
requirepass foobared
# 也可以通过命令去设置密码
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> CONFIG GET requirepass #获取Redis密码,默认没有密码
1) "requirepass"
2) ""
127.0.0.1:6379> CONFIG set requirepass 123456 # 设置密码
OK
127.0.0.1:6379> ping
(error) NOAUTH Authentication required. # 没有进行密码认证
127.0.0.1:6379> AUTH 123456 # 密码认证
OK
127.0.0.1:6379> ping
PONG

CLIENTS client

# 对客户端的连接进行限制
# 最大连接数量
maxclients 10000
# Redis最大内存容量
maxmemory <bytes>
# 内存上限的处理策略
# volatile-lru 		====> 设置了过期时间并且最近最少使用的key进行删除
# allkeys-lru 		====> 最近最少使用的所有的key进行删除
# volatile-lfu 	 	====> 设置了过期时间并且使用频率最低的key进行杀出
# allkeys-lfu   	====> 使用频率最低的所有的key进行删除
# volatile-random 	====> 随机删除有过期时间的key
# allkeys-random  	====> 随机移除任何一个key
# volatile-ttl   	====> 随机移除一个快要过期的key
# noeviction      	====> 不删除任何key,返回写入操作错误
maxmemory-policy noeviction

APPEND ONLY MODE AOF configuration

# 持久化配置的一种
# 默认不开启aof模式,默认使用rdb持久化
appendonly no
# aof持久化文件名
appendfilename "appendonly.aof"
# 同步策略
# 始终同步,消耗性能
appendfsync always
# 每秒进行一次
appendfsync everysec
# 不同步,
appendfsync no

Guess you like

Origin blog.csdn.net/weixin_45481406/article/details/109498149