启动可以指定相关的配置文件
1、单位
单位换算,不区分大小写
11 # 1k => 1000 bytes
12 # 1kb => 1024 bytes
13 # 1m => 1000000 bytes
14 # 1mb => 1024*1024 bytes
15 # 1g => 1000000000 bytes
16 # 1gb => 1024*1024*1024 bytes
17 #
18 # units are case insensitive so 1GB 1Gb 1gB are all the same.
2、包含
多个配置文件包含进来
35 # include /path/to/local.conf
36 # include /path/to/other.conf
3、通用
48 # By default, if no "bind" configuration directive is specified, Redis listens
49 # for connections from all the network interfaces available on the server.
50 # It is possible to listen to just one or multiple selected interfaces using
51 # the "bind" configuration directive, followed by one or more IP addresses.
52 #
53 # Examples:
54 #
55 # bind 192.168.1.100 10.0.0.1
56 # bind 127.0.0.1 ::1
57 #
58 # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
59 # internet, binding to all the interfaces is dangerous and will expose the
60 # instance to everybody on the internet. So by default we uncomment the
61 # following bind directive, that will force Redis to listen only into
62 # the IPv4 loopback interface address (this means Redis will be able to
63 # accept connections only from clients running into the same computer it
64 # is running).
65 #
66 # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
67 # JUST COMMENT THE FOLLOWING LINE.
68 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
69 bind 127.0.0.1 # 绑定地址
88 protected-mode yes # 是否保护模式,为了安全,默认开启
92 port 6379
222 daemonize yes # 是否以守护进程方式运行(后台运行),默认no
233 supervised no # 管理守护进程,默认no
244 pidfile /var/run/redis_6379.pid # 如果以守护进程的方式运行,就需要指定一个pid文件
246 # Specify the server verbosity level.
247 # This can be one of:
248 # debug (a lot of information, useful for development/testing)
249 # verbose (many rarely useful info, but not a mess like the debug level)
250 # notice (moderately verbose, what you want in production probably)
251 # warning (only very important / critical messages are logged)
252 loglevel notice # 日志级别
257 logfile "" # 生成的文件位置名称
272 databases 16 # 数据库数量
280 always-show-logo yes # 是否显示启动时的logo
3、快照配置
快照配置,持久化,在规定的时间内,执行了多少次操作,则会持久化到文件.rdb .aof文件
持久化规则,内存数据库,没有持久化,断电即失
304 save 900 1 # 如果900s内只要有一个key进行了修改
305 save 300 10
306 save 60 10000
321 stop-writes-on-bgsave-error yes # 持久化出现错误时,是否继续工作
327 rdbcompression yes # 是否压缩rdb文件,需要消耗cpu资源
336 rdbchecksum yes # 保存rdb文件的时候,是否校验rdb文件
362 dir ./ # rdb文件默认的保存目录
336 rdbchecksum yes
337
338 # The filename where to dump the DB
339 dbfilename dump.rdb
4、安全配置(SECURITY)
786 # requirepass foobared # 默认密码是空的
127.0.0.1:6379> ping
PONG
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> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456 # 验证密码
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config set requirepass ""
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
5、AOF配置
1059 appendonly no # 默认不开启,采用rdb持久化
1060
1061 # The name of the append only file (default: "appendonly.aof")
1062
1063 appendfilename "appendonly.aof" # 持久化文件的名字
1088 # appendfsync always # 每次修改都会同步,消耗性能
1089 appendfsync everysec # 每秒都同步一次,但是可能丢失这1s的数据
1090 # appendfsync no # 不同步,操作系统自己同步数据,速度最快
6、其他
客户端的一些限制
829 # maxclients 10000 # 同时最大连接的客户端
856 # maxmemory <bytes> # 最大内存设置
887 # maxmemory-policy noeviction # 内存满了之后采取何种策略
# noeviction(默认策略):对于写请求不再提供服务,直接返回错误(DEL请求和部分特殊请求除外)
# allkeys-lru:从所有key中使用LRU算法进行淘汰
# volatile-lru:从设置了过期时间的key中使用LRU算法进行淘汰
# allkeys-random:从所有key中随机淘汰数据
# volatile-random:从设置了过期时间的key中随机淘汰
# volatile-ttl:在设置了过期时间的key中,根据key的过期时间进行淘汰,越早过期的越优先被淘汰
981 lazyfree-lazy-eviction no
982 lazyfree-lazy-expire no
983 lazyfree-lazy-server-del no
984 replica-lazy-flush no
985
986 # It is also possible, for the case when to replace the user code DEL calls
987 # with UNLINK calls is not easy, to modify the default behavior of the DEL
988 # command to act exactly like UNLINK, using the following configuration
989 # directive:
990
991 lazyfree-lazy-user-del no