1、配置文件 unit单位 对大小写不敏感
# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf
# 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、可以包含多个配置文件引用
################################## 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.
#
# Note that 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 /path/to/other.conf
3、网络部分,重要的有三个
################################## NETWORK #####################################
bind 127.0.0.1 #绑定ip地址
protected-mode yes #保护模式,默认开启
port 6379 #端口配置
4、通用配置
################################# GENERAL #####################################
daemonize yes #是否以守护进程开启(后台运行),默认为no
supervised no #管理守护进程,默认为no
pidfile /var/run/redis_6379.pid #配置文件的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 #日志极别
# Specify the log file name. Also the empty string can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile "" #生成的日志文件位置名
# Set the number of databases. The default database is DB 0, you can select
# a different one on a per-connection basis using SELECT <dbid> where
# dbid is a number between 0 and 'databases'-1
databases 16 #数据库的数量,默认有16个数据库
always-show-logo yes #是否显示redis 启动 logo
5、快照
################################ SNAPSHOTTING ################################
#持久化(生成快照),在规定时间内,执行了多少次操作后会持久化到文件.rdb、.aof
#redis是内存数据库,如果没有持久化,数据就会丢失
save 3600 1 #如果900秒内,至少有1个key进行了修改,这个时候就进行持久化操作
save 300 100 #如果300秒内,至少有100个key进行了修改,这个时候就进行持久化操作
save 60 10000 #如果60秒内,至少有10000个key进行了修改,这个时候就进行持久化操作
stop-writes-on-bgsave-error yes #持久化过程中出现错误是否依旧进行工作
rdbcompression yes #是否压缩rdb文件,需要消耗一些cpu资源
rdbchecksum yes #保存rdb文件的时候,是否错误校验,如果出错了,进行自行修复
dir ./ #持久化生成rdb文件的目录,默认当前文件夹下
6、REPLICATION 主从复制,可在配置文件中设置主机的ip+端口+密码。
也可通过命令进行设置。Redis主从复制_MJlife的博客-CSDN博客
################################# REPLICATION #################################
# Master-Replica replication. Use replicaof to make a Redis instance a copy of
# another Redis server. A few things to understand ASAP about Redis replication.
#
# +------------------+ +---------------+
# | Master | ---> | Replica |
# | (receive writes) | | (exact copy) |
# +------------------+ +---------------+
#
# 1) Redis replication is asynchronous, but you can configure a master to
# stop accepting writes if it appears to be not connected with at least
# a given number of replicas.
# 2) Redis replicas are able to perform a partial resynchronization with the
# master if the replication link is lost for a relatively small amount of
# time. You may want to configure the replication backlog size (see the next
# sections of this file) with a sensible value depending on your needs.
# 3) Replication is automatic and does not need user intervention. After a
# network partition replicas automatically try to reconnect to masters
# and resynchronize with them.
#
# replicaof <masterip> <masterport>
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the replica to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
#
# masterauth <master-password>
7、安全
################################## SECURITY ###################################
requirepass 123456 #密码设置,默认为空
也可以通过命令进行设置密码
![](https://i-blog.csdnimg.cn/blog_migrate/e412d4c461106f73f295c7161d2ca2ad.png)
8、限制CLIENTS
################################### CLIENTS ####################################
maxclients 10000 #最大客户端数
maxmemory <bytes> #最大内存
# volatile-lru -> Evict using approximated LRU, only keys with an expire set.只对设置了过期时间的key进行LRU(默认值)
# allkeys-lru -> Evict any key using approximated LRU.删除lru算法的key
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having an expire set.随机删除即将过期key
# allkeys-random -> Remove a random key, any key.随机删除
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)删除即将过期的
# noeviction -> Don't evict anything, just return an error on write operations.永不过期,返回错误
maxmemory-policy noeviction #内存到达上限后的处理策略
9、APPEND ONLY 模式,aof配置
############################## APPEND ONLY MODE ###############################
appendonly no #默认不开启aof模式,默认是使用rdb模式持久化,在大部分的情况下,rdb已经完全够用
appendfilename "appendonly.aof" #持久化文件的名字
# appendfsync always #每次修改了值都会sync,比较消耗性能
appendfsync everysec #每秒执行一次sync同步,可能会丢失这一秒的数据,
# appendfsync no #关闭sync同步