# 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对大小写不敏感
#
# include /path/to/local.conf
# include /path/to/other.conf
类似于Spring中的import,include
#
# bind 127.0.0.1 #绑定的ip,如果想支持远程连接可以改成自己的ip或者*
protected-mode yes #保护模式
port 6379 #端口
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 ""日志文件位置名
database 16 #数据库的数量,默认是16个数据库
always-show-logo yes #是否总是显示logo
redis是内存数据库,如果没有持久化,那么数据断电即失!
save 900 1 #如果900秒内,如果至少有个一key进行了修改,我们就进行持久化操作
save 300 10 #如果300秒内,如果至少有个10key进行了修改,我们就进行持久化操作
save 60 10000 #如果60秒内,如果至少有个10000key进行了修改,我们就进行持久化操作
stop-writes-on-bgsave-error yes #持久化如果出错,是否还需要继续工作
rdbcompression yes #是否压缩rdb文件,需要消耗cpu资源!
rdbchecksum yes #保存rdb文件的时候,进行错误的检查校验!
dir ./ #rdb文件保存的目录!
#配置文件设置密码
requirepass 123456 #设置密码默认是没有密码的
#命令设置密码
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass "123456"
OK
127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456 #使用密码进行登录
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "123456"
maxclients 10000 #设置最大连接客户端数
maxmemory <bytes> #redis配置最大的内存容量
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 : 永不过期,返回错误
append only模式 aof模式
appendonly no #默认不开启aof模式,默认是rdb方式持久化的,在大部分所有情况下,rdb完全够用
appendfilename "appendonly.aof" #持久化文件名字
# appendfsync always #每次修改都会sync,消耗性能
appendfsync everysec #每秒执行一次sync,可能会丢失这一秒的数据
# appendfsync no #不执行sync,这个时候操作系统自己同步数据,速度最快!