启动的时候通过配置文件来启动
1.配置文件unit单位对大小写不敏感
包含
类似于import
网络
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 默认为16个数据库
always-show-logo yes 是否总是显示logo
快照
redis是内存数据库,如果没有持久化,那么数据断电即失
save 900 1 如果900s内至少有1个key进行了修改,我们进行持久化操作
save 300 10 如果300s内至少有10个key进行了修改,我们进行持久化操作
save 60 10000 如果60s内至少有10000个key进行了修改,我们进行持久化操作
stop-writes-on-bgsave-error yes 持久化如果出错是否要持续工作
rdbcompression yes 是否压缩rdb文件,需要消耗cpu资源
rdbchecksum yes 保存rdb文件的时候进行错误的检查校验
dir ./ rdb文件保存的目录
SECURITY
可以设置redis密码,默认是没有密码的
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
1) "requirepass"
2) "123456"
限制CLIENTS
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方式持久的
appendfilename "appendonly.aof" 持久化文件的名字
# appendfsync always 每次修改都会sync 消耗性能
appendfsync everysec 每秒执行一次sync,可能会丢失ls的数据
# appendfsync no 不执行sync,这个时候操作系统自己同步数据