- 单位
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same. redis配置文件对大小写不敏感
- 包含
################################## INCLUDES ###################################
# 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.
#
# Notice 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
可以将多个配置问价包含进来
- 网络
bind 127.0.0.1 #绑定ip
protected-mode no #保护模式
port 6379 #端口设置
- 通用
daemonize yes #以守护进程的方式运行,默认是no,我们需要手动开启
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
#900秒内,至少有一个key修改,进行持久化
save 900 1
#300秒内,至少有10个key修改,进行持久化
save 300 10
#60秒内,至少有10000key修改,进行持久化
save 60 10000
stop-writes-on-bgsave-error yes #如果持久化出错是否继续工作
rdbcompression yes #是否压缩rdb文件
rdbchecksum yes #保存rdb文件时,进行错误校验
dir ./ #rdb文件保存目录
- 安全
requirepass 123456 #设置密码
- 限制
maxclients 10000 #最大客户端连接数
maxmemory <bytes> #配置redis最大的内存容量
maxmemory-policy noeviction #内存到达上限之后的处理策略
- AOF配置
appendonly no #默认是不开启aof的,大部分情况下,rdb完全够用
appendfilename "appendonly.aof" #持久化的文件名字
#appendfsync always #每次修改都会sync,消耗性能
appendfsync everysec #每秒执行一次sync,可能会丢失一秒数据
#appendfsync no #不执行sync,这个时候操作系统自己同步数据,速度最快。