单位
# Redis configuration file example
# 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. #对大小写不敏感
包含:INCLUDES 可以将其他文件配置进来
################################## 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 c:\path\to\other.conf
网络:NETWORK
bind 127.0.0.1 # 绑定的ip
protected-mode yes #是否收保护的模式
port 6379 # 端口设置
通用配置:GENERAL
daemonize yes #以守护进程的方式运行,默认是no,需要自己开启为yes
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 # 默认数据库数量
always-show-logo yes #是否显示logo
快照:SNAPSHOTTING
在规定时间内,执行多少次操作,就会持久化到文件, .rdb文件/.aof文件
redis是内存数据库,如果没有持久化,断电后数据就没了
save 900 1 #如果900秒内,至少有一个kye进行了修改,那么就进行持久化操作
save 300 10 #300,至少有10个kye进行了修改,那么就进行持久化操作
save 60 10000 #如果60秒内,至少有10000个kye进行了修改,那么就进行持久化操作
stop-writes-on-bgsave-error yes #持久化出现错误后,是否继续进行工作
rdbcompression yes #是否压缩rdb文件,默认开启,会消耗cpu资源
rdbchecksum yes #保存 rbd文件时,进行错误检查
dir ./ #rbd文件保存的文件目录
dump.rdb #持久化的文件名(rdb保存的文件是dump.rdb)
复制:REPLICATION
slaveof <masterip> <masterport> #设置地址、端口
masterauth <master-password> #设置主机密码
安全:SECURITY
这里可以设置redis,默认没有密码
localhost:0>config get requirepass #查看redis密码
1) "requirepass"
2) ""
localhost:0>config set requirepass "123456" #设置密码
"OK"
localhost:0>config get requirepass #查看密码,没有权限,需要登录
"NOAUTH Authentication required."
localhost:0>auth 123456 #验证密码
"OK"
localhost:0>config get requirepass #查看成功
1) "requirepass"
2) "123456"
localhost:0>save #保存 (save命令会阻塞Redis服务器进程,直到RDB文件创建完毕为止在此期间服务器不能处理任何命令的请求)
"OK"
限制:clients
maxclients 10000 # 设置redis最大客户端连接数量
maxmemory <bytes> #最大内存容量
maxmemory-policy noeviction #内存达到上线处理策略
1、volatile-lru:只对设置了过期时间的key进行LRU(默认值)
2、allkeys-lru : 删除lru算法的key
3、volatile-random:随机删除即将过期key
4、allkeys-random:随机删除
5、volatile-ttl : 删除即将过期的
6、noeviction : 永不过期,返回错误
aof配置:APPEND ONLY MODE
appendonly no #默认不开启aof模式,因为默认使用rdb持久化,大部分情况下rdb完全够用
appendfilename "appendonly.aof" #持久化文件名
# appendfsync always #每次修改都会 sync,消耗性能
appendfsync everysec #每秒执行一次 sync,可能会丢失这一秒的数
# appendfsync no #不执行sync ,这个时候操作系统自己执行同步,速度是最快的