【redis】redis-config详解
狂神老师的视频地址:https://space.bilibili.com/95256449
这里用window下的配置文件配合来看
1、单位
可以看到,可以在配置文件里设置单位,并且对大小写不敏感
# 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.
2、包含
和springboot配置文件类似,配置文件可以包含其他配置文件
# 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
3、网络
bind 127.0.0.1 #绑定IP
protected-mode yes #保护模式
port 6379 #端口设置
4、通过设置
设置密码,可在参数文件中设置,一般在命令中设置
C:\Users\86155>redis-cli
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass
(error) ERR Unknown subcommand or wrong number of arguments for 'set'. Try CONFIG HELP.
127.0.0.1:6379> config set requirepass 123456
# maxclients 10000 #最大并发数
# 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 : 永不过期,返回错误
APPEND ONLY MODE
appendonly no #默认不开启 aof,默认使用rdb,一般够用
appendfilename "appendonly.aof" #持久化文件的名字
# appendfsync always #每次修改都会同步
appendfsync everysec #每秒执行一次同步,可能会丢失这1s的数据
# appendfsync no #不同步
具体的配置Redis持久化会记录