Redis(1.5)Redis配置文件(4.0.14)

4.0.14 常用配置

1bind 127.0.0.1 # 默认绑定本地,不写的话任何地址都可以访问 2protected-mode yes    #保护模式,如果没有设置bind 配置地址,也没有设置任何密码,则只允许本地连接 3port 6379         # 端口号 6379 4timeout 0          # 此参数为设置客户端空闲超过timeout,服务端会断开连接,为0则服务端不会主动断开连接,不能小于05daemonize no        #no为前台运行,yes是后台运行 6pidfile /var/run/redis_6379.pid --pid文件路径 7loglevel notice      #消息级别,debug(很多信息,方便开发、测试),verbose(许多有用的信息,但是没有debug级别信息多),notice(适当的日志级别,适合生产环境),warn(只有非常重要的信息) 8logfile ""         #指定了记录日志的文件。空字符串的话,日志会打印到标准输出设备。后台运行的redis标准输出是/dev/null9databases 16       #数据库的数量默认16,默认使用的数据库是DB 0。可以通过”SELECT “命令选择一个db 10save 900 1         #持久化频率,save 900 1,900秒内有1个以上的key改动则启用该持久化频率,下面的以此类推 11save 300 10 12save 60 10000 13stop-writes-on-bgsave-error yes #当RDB持久化出现错误后,是否依然进行继续进行工作,yes:不能进行工作,no:可以继续进行工作,可以通过info中的rdb_last_bgsave_status了解RDB持久化是否有错误 14rdbcompression yes      #使用压缩rdb文件,rdb文件压缩使用LZF压缩算法,yes:压缩,但是需要一些cpu的消耗。no:不压缩,需要更多的磁盘空间  15rdbchecksum yes       #是否校验rdb文件。从rdb格式的第五个版本开始,在rdb文件的末尾会带上CRC64的校验和。这跟有利于文件的容错性,但是在保存rdb文件的时候,会有大概10%的性能损耗,所以如果你追求高性能,可以关闭该配置。 16dbfilename dump.rdb     #rdb 文件名 17dir ./             #数据目录,数据库的写入会在这个目录。rdb、aof文件也会写在这个目录 18slave-serve-stale-data yes #当从库同主机失去连接或者复制正在进行,从机库有两种运行方式:1) 如果slave-serve-stale-data设置为yes(默认设置),从库会继续响应客户端的请求。                 # 2) 如果slave-serve-stale-data设置为no,除去INFOSLAVOF命令之外的任何请求都会返回一个错误”SYNC with master in progress”。 19slave-read-only yes      #从数据库只读 20repl-diskless-sync no    #是否使用socket方式复制数据。目前redis复制提供两种方式,disk和socket。如果新的slave连上来或者重连的slave无法部分同步,就会执行全量同步,master会生成rdb文件。                 #有2种方式:disk方式是master创建一个新的进程把rdb文件保存到磁盘,再把磁盘上的rdb文件传递给slave。socket是master创建一个新的进程,直接把rdb文件以socket的方式发给slave。                 #disk方式的时候,当一个rdb保存的过程中,多个slave都能共享这个rdb文件。socket的方式就的一个个slave顺序复制。在磁盘速度缓慢,网速快的情况下推荐用socket方式。 21repl-diskless-sync-delay 5    #diskless复制的延迟时间,防止设置为0。一旦复制开始,节点不会再接收新slave的复制请求直到下一个rdb传输。所以最好等待一段时间,等更多的slave连上来 22repl-disable-tcp-nodelay no    #是否禁止复制tcp链接的tcp nodelay参数,可传递yes或者no。默认是no,即使用tcp nodelay。如果master设置了yes来禁止tcp nodelay设置,在把数据复制给slave的时候,会减少包的数量和更小的网络带宽。                    #但是这也可能带来数据的延迟。默认我们推荐更小的延迟,但是在数据量传输很大的场景下,建议选择yes。 23#requirepass foobared        #redis密码,默认该选项被注释了#maxclients 10000          #最大客户端连接数,即并发最大值,默认该选项被注释了#maxmemory <bytes>         #最大内存值,如果将要超出最大内存,则redis会释放无用key,如果无法释放或内存已经到达最大值,则redis无法写入,只能利用swap等进行读取操作; 24appendonly no            #默认为no,yes为开启aof 25appendfilename "appendonly.aof" #aof文件名称  26appendfsync everysec        #aof文件策略,everysec,no,always. 27#内存策略#(1)设置key的过期时间 expire (过期时间):expire andkey 1000  --单位为秒#(2)算法策略

# volatile-lru -> Evict using approximated LRU among the keys with an expire set. 
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU among the keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key among the ones with an expire set.
# 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.

volatile-lru #设置超时时间的数据中,删除最不常用的数据
allkeys-lru #查询所有Key中最不常用的数据进行删除,这是应用最广泛的策略
volatile-lfu #从所有配置了过期时间的键中删除使用频率最少的键
allkeys-lfu #从所有键中驱逐使用频率最少的键
volatile-random #在已经设定了超时的数据中随机删除
allkeys-random #查询所有的key之后,随机删除。
volatile-ttl #查询全部设定超时时间的数据之后排序,将马上要过期的数据进行删除。
noeviction #默认--不删除任何东西,内存溢出后返回报错

1#redis cluster参数 2 3cluster-enabled<yes/no>:如果是,则在特定Redis实例中启用Redis群集支持。否则,实例像往常一样作为独立实例启动。 4cluster-config-file<filename>:请注意,尽管有此选项的名称,但这不是用户可编辑的配置文件,而是每次发生更改时Redis群集节点自动保持群集配置(基本上是状态)的文件,为了能够在启动时重新阅读它。该文件列出了集群中其他节点,状态,持久变量等内容。由于某些消息接收,通常会将此文件重写并刷新到磁盘上。 5cluster-node-timeout<milliseconds>:Redis群集节点不可用的最长时间,不会被视为失败。如果主节点的可访问时间超过指定的时间,则其从属节点将进行故障转移。此参数控制Redis群集中的其他重要事项。值得注意的是,在指定时间内无法访问大多数主节点的每个节点都将停止接受查询。 6cluster-slave-validity-factor<factor>:如果设置为零,则从站将始终尝试对主站进行故障切换,而不管主站和从站之间的链路是否保持断开连接的时间长短。如果该值为正,则计算最大断开时间作为节点超时值乘以此选项提供的因子,如果节点是从属节点,则如果主链接断开连接的时间超过指定的时间,则不会尝试启动故障转移。例如,如果节点超时设置为5秒,并且有效性因子设置为10,则从主设备断开超过50秒的从设备将不会尝试故障转移其主设备。请注意,如果没有从站能够对其进行故障转移,则任何不同于零的值都可能导致Redis群集在主站发生故障后不可用。在这种情况下,只有当原始主服务器重新加入群集时,群集才会返回。 7cluster-migration-barrier<count>:主服务器将保持连接的最小从服务器数,以便另一个从服务器迁移到不再由任何从服务器覆盖的主服务器。有关详细信息,请参阅本教程中有关副本迁移的相应部分。 cluster-require-full-coverage<yes/no>:如果设置为yes,则默认情况下,如果任何节点未覆盖某个百分比的密钥空间,则集群将停止接受写入。如果该选项设置为no,即使只能处理有关键子集的请求,群集仍将提供查询。 8 9#RDB文件参数 10 11save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yes #后台存储错误停止写rdbcompression yes #在进行镜像备份时,是否压缩。压缩需要更多CPU,不压缩需要更多磁盘空间rdbchecksum yes #一个CRC64的校验被放在了文件末尾,当存储或者加载rdb文件时会有10%性能问题,为了性能可以关闭这个配置dbfilename dump.rdb #快照的文件名dir /var/local #快照的存放目录#AOF文件参数appendonly yes      #启用aof持久化#appendfsync always   #每收到命令就立即强制写入磁盘,效率最慢,但是保证完全的持久化,不推荐使用appendfsync everysec   #默认为该值,每秒强制写入磁盘一次,性能和持久化的折中选择,推荐使用#appendfsync no    #完全依赖os,性能最好,持久化每保证(操作系统自身按情况同步)no-appendfsync-on-rewrite yes   #正在导出rdb快照的过程中,是否停止同步aofauto-aof-rewrite-percentage 100    #aof文件大写比起上次重写时的大小,增长率100%时,重写auto-aof-rewrite-min-size 64mb      #aof文件,至少超过64M时,才会有重写操作 12

转载详解参考:

1#redis.conf 2# Redis configuration file example. 3# ./redis-server /path/to/redis.conf 4 5################################## INCLUDES ################################### 6#这在你有标准配置模板但是每个redis服务器又需要个性设置的时候很有用。 7# include /path/to/local.conf 8# include /path/to/other.conf 9 10################################ GENERAL ##################################### 11 12#是否在后台执行,yes:后台运行;no:不是后台运行(老版本默认) 13daemonize yes 14 15 #3.2里的参数,是否开启保护模式,默认开启。要是配置里没有指定bind和密码。 16 #开启该参数后,redis只会本地进行访问,拒绝外部访问。要是开启了密码和bind, 17 #可以开启。否则最好关闭,设置为no。 18 protected-mode yes 19#redis的进程文件 20pidfile /var/run/redis/redis-server.pid 21 22#redis监听的端口号。 23port 6379 24 25#此参数确定了TCP连接中已完成队列(完成三次握手之后)的长度, 26# 当然此值必须不大于Linux系统定义的/proc/sys/net/core/somaxconn值 27#,默认是511,而Linux的默认参数值是12828#当系统并发量大并且客户端速度缓慢的时候,可以将这二个参数一起参考设定。 29#该内核参数默认值一般是128,对于负载很大的服务程序来说大大的不够。 30#一般会将它修改为2048或者更大。 31#在/etc/sysctl.conf中添加:net.core.somaxconn = 204832#然后在终端中执行sysctl -p。 33tcp-backlog 511 34 35#指定 redis 只接收来自于该 IP 地址的请求,如果不进行设置,那么将处理所有请求 36bind 127.0.0.1 37 38#配置unix socket来让redis支持监听本地连接。 39# unixsocket /var/run/redis/redis.sock 40#配置unix socket使用文件的权限 41# unixsocketperm 700 42 43# 此参数为设置客户端空闲超过timeout,服务端会断开连接,为0则服务端不会主动断开连接,不能小于044timeout 0 45 46#tcp keepalive参数。如果设置不为0,就使用配置tcp的SO_KEEPALIVE值,使用keepalive有两个好处:检测挂掉的对端。降低中间设备出问题而导致网络看似连接却已经与对端端口的问题。在Linux内核中,设置了keepalive,redis会定时给对端发送ack。检测到对端关闭需要两倍的设置值。 47tcp-keepalive 0 48 49#指定了服务端日志的级别。级别包括:debug(很多信息,方便开发、测试),verbose(许多有用的信息,但是没有debug级别信息多),notice(适当的日志级别,适合生产环境),warn(只有非常重要的信息) 50loglevel notice 51 52#指定了记录日志的文件。空字符串的话,日志会打印到标准输出设备。后台运行的redis标准输出是/dev/null53logfile /var/log/redis/redis-server.log 54 55#是否打开记录syslog功能 56# syslog-enabled no 57 58#syslog的标识符。 59# syslog-ident redis 60 61#日志的来源、设备 62# syslog-facility local0 63 64#数据库的数量,默认使用的数据库是DB 0。可以通过”SELECT “命令选择一个db 65databases 16 66 67################################ SNAPSHOTTING ################################ 68# 快照配置 69# 注释掉“save”这一行配置项就可以让保存数据库功能失效 70# 设置sedis进行数据库镜像的频率。 71# 900秒(15分钟)内至少1个key值改变(则进行数据库保存--持久化) 72# 300秒(5分钟)内至少10个key值改变(则进行数据库保存--持久化) 73# 60秒(1分钟)内至少10000个key值改变(则进行数据库保存--持久化) 74save 900 1 75save 300 10 76save 60 10000 77 78#当RDB持久化出现错误后,是否依然进行继续进行工作,yes:不能进行工作,no:可以继续进行工作,可以通过info中的rdb_last_bgsave_status了解RDB持久化是否有错误 79stop-writes-on-bgsave-error yes 80 81#使用压缩rdb文件,rdb文件压缩使用LZF压缩算法,yes:压缩,但是需要一些cpu的消耗。no:不压缩,需要更多的磁盘空间 82rdbcompression yes 83 84#是否校验rdb文件。从rdb格式的第五个版本开始,在rdb文件的末尾会带上CRC64的校验和。这跟有利于文件的容错性,但是在保存rdb文件的时候,会有大概10%的性能损耗,所以如果你追求高性能,可以关闭该配置。 85rdbchecksum yes 86 87#rdb文件的名称 88dbfilename dump.rdb 89 90#数据目录,数据库的写入会在这个目录。rdb、aof文件也会写在这个目录 91dir /var/lib/redis 92 93################################# REPLICATION ################################# 94#复制选项,slave复制对应的master。 95# slaveof <masterip> <masterport> 96 97#如果master设置了requirepass,那么slave要连上master,需要有master的密码才行。masterauth就是用来配置master的密码,这样可以在连上master后进行认证。 98# masterauth <master-password> 99 100#当从库同主机失去连接或者复制正在进行,从机库有两种运行方式:1) 如果slave-serve-stale-data设置为yes(默认设置),从库会继续响应客户端的请求。2) 如果slave-serve-stale-data设置为no,除去INFOSLAVOF命令之外的任何请求都会返回一个错误”SYNC with master in progress”。 101slave-serve-stale-data yes 102 103#作为从服务器,默认情况下是只读的(yes),可以修改成NO,用于写(不建议)。 104slave-read-only yes 105 106#是否使用socket方式复制数据。目前redis复制提供两种方式,disk和socket。如果新的slave连上来或者重连的slave无法部分同步,就会执行全量同步,master会生成rdb文件。有2种方式:disk方式是master创建一个新的进程把rdb文件保存到磁盘,再把磁盘上的rdb文件传递给slave。socket是master创建一个新的进程,直接把rdb文件以socket的方式发给slave。disk方式的时候,当一个rdb保存的过程中,多个slave都能共享这个rdb文件。socket的方式就的一个个slave顺序复制。在磁盘速度缓慢,网速快的情况下推荐用socket方式。 107repl-diskless-sync no 108 109#diskless复制的延迟时间,防止设置为0。一旦复制开始,节点不会再接收新slave的复制请求直到下一个rdb传输。所以最好等待一段时间,等更多的slave连上来。 110repl-diskless-sync-delay 5 111 112#slave根据指定的时间间隔向服务器发送ping请求。时间间隔可以通过 repl_ping_slave_period 来设置,默认10秒。 113# repl-ping-slave-period 10 114 115#复制连接超时时间。master和slave都有超时时间的设置。master检测到slave上次发送的时间超过repl-timeout,即认为slave离线,清除该slave信息。slave检测到上次和master交互的时间超过repl-timeout,则认为master离线。需要注意的是repl-timeout需要设置一个比repl-ping-slave-period更大的值,不然会经常检测到超时。 116# repl-timeout 60 117 118#是否禁止复制tcp链接的tcp nodelay参数,可传递yes或者no。默认是no,即使用tcp nodelay。如果master设置了yes来禁止tcp nodelay设置,在把数据复制给slave的时候,会减少包的数量和更小的网络带宽。但是这也可能带来数据的延迟。默认我们推荐更小的延迟,但是在数据量传输很大的场景下,建议选择yes。 119repl-disable-tcp-nodelay no 120 121#复制缓冲区大小,这是一个环形复制缓冲区,用来保存最新复制的命令。这样在slave离线的时候,不需要完全复制master的数据,如果可以执行部分同步,只需要把缓冲区的部分数据复制给slave,就能恢复正常复制状态。缓冲区的大小越大,slave离线的时间可以更长,复制缓冲区只有在有slave连接的时候才分配内存。没有slave的一段时间,内存会被释放出来,默认1m。 122# repl-backlog-size 5mb 123 124#master没有slave一段时间会释放复制缓冲区的内存,repl-backlog-ttl用来设置该时间长度。单位为秒。 125# repl-backlog-ttl 3600 126 127#当master不可用,Sentinel会根据slave的优先级选举一个master。最低的优先级的slave,当选master。而配置成0,永远不会被选举。 128slave-priority 100 129 130#redis提供了可以让master停止写入的方式,如果配置了min-slaves-to-write,健康的slave的个数小于N,mater就禁止写入。master最少得有多少个健康的slave存活才能执行写命令。这个配置虽然不能保证N个slave都一定能接收到master的写操作,但是能避免没有足够健康的slave的时候,master不能写入来避免数据丢失。设置为0是关闭该功能。 131# min-slaves-to-write 3 132 133#延迟小于min-slaves-max-lag秒的slave才认为是健康的slave。 134# min-slaves-max-lag 10 135 136# 设置1或另一个设置为0禁用这个特性。 137# Setting one or the other to 0 disables the feature. 138# By default min-slaves-to-write is set to 0 (feature disabled) and 139# min-slaves-max-lag is set to 10. 140 141################################## SECURITY ################################### 142#requirepass配置可以让用户使用AUTH命令来认证密码,才能使用其他命令。这让redis可以使用在不受信任的网络中。为了保持向后的兼容性,可以注释该命令,因为大部分用户也不需要认证。使用requirepass的时候需要注意,因为redis太快了,每秒可以认证15w次密码,简单的密码很容易被攻破,所以最好使用一个更复杂的密码。 143# requirepass foobared 144 145#把危险的命令给修改成其他名称。比如CONFIG命令可以重命名为一个很难被猜到的命令,这样用户不能使用,而内部工具还能接着使用。 146# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 147 148#设置成一个空的值,可以禁止一个命令 149# rename-command CONFIG "" 150################################### LIMITS #################################### 151 152# 设置能连上redis的最大客户端连接数量。默认是10000个客户端连接。由于redis不区分连接是客户端连接还是内部打开文件或者和slave连接等,所以maxclients最小建议设置到32。如果超过了maxclients,redis会给新的连接发送’max number of clients reached’,并关闭连接。 153# maxclients 10000 154 155#redis配置的最大内存容量。当内存满了,需要配合maxmemory-policy策略进行处理。注意slave的输出缓冲区是不计算在maxmemory内的。所以为了防止主机内存使用完,建议设置的maxmemory需要更小一些。 156# maxmemory <bytes> 157 158#内存容量超过maxmemory后的处理策略。 159#volatile-lru:利用LRU算法移除设置过过期时间的key。 160#volatile-random:随机移除设置过过期时间的key。 161#volatile-ttl:移除即将过期的key,根据最近过期时间来删除(辅以TTL162#allkeys-lru:利用LRU算法移除任何key。 163#allkeys-random:随机移除任何key。 164#noeviction:不移除任何key,只是返回一个写错误。 165#上面的这些驱逐策略,如果redis没有合适的key驱逐,对于写命令,还是会返回错误。redis将不再接收写请求,只接收get请求。写命令包括:set setnx setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby getset mset msetnx exec sort。 166# maxmemory-policy noeviction 167 168#lru检测的样本数。使用lru或者ttl淘汰算法,从需要淘汰的列表中随机选择sample个key,选出闲置时间最长的key移除。 169# maxmemory-samples 5 170 171############################## APPEND ONLY MODE ############################### 172#默认redis使用的是rdb方式持久化,这种方式在许多应用中已经足够用了。但是redis如果中途宕机,会导致可能有几分钟的数据丢失,根据save来策略进行持久化,Append Only File是另一种持久化方式,可以提供更好的持久化特性。Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件,每次启动时Redis都会先把这个文件的数据读入内存里,先忽略RDB文件。 173appendonly no 174 175#aof文件名 176appendfilename "appendonly.aof" 177 178#aof持久化策略的配置 179#no表示不执行fsync,由操作系统保证数据同步到磁盘,速度最快。 180#always表示每次写入都执行fsync,以保证数据同步到磁盘。 181#everysec表示每秒执行一次fsync,可能会导致丢失这1s数据。 182appendfsync everysec 183 184# 在aof重写或者写入rdb文件的时候,会执行大量IO,此时对于everysec和always的aof模式来说,执行fsync会造成阻塞过长时间,no-appendfsync-on-rewrite字段设置为默认设置为no。如果对延迟要求很高的应用,这个字段可以设置为yes,否则还是设置为no,这样对持久化特性来说这是更安全的选择。设置为yes表示rewrite期间对新写操作不fsync,暂时存在内存中,等rewrite完成后再写入,默认为no,建议yes。Linux的默认fsync策略是30秒。可能丢失30秒数据。 185no-appendfsync-on-rewrite no 186 187#aof自动重写配置。当目前aof文件大小超过上一次重写的aof文件大小的百分之多少进行重写,即当aof文件增长到一定大小的时候Redis能够调用bgrewriteaof对日志文件进行重写。当前AOF文件大小是上次日志重写得到AOF文件大小的二倍(设置为100)时,自动启动新的日志重写过程。 188auto-aof-rewrite-percentage 100 189#设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写 190auto-aof-rewrite-min-size 64mb 191 192#aof文件可能在尾部是不完整的,当redis启动的时候,aof文件的数据被载入内存。重启可能发生在redis所在的主机操作系统宕机后,尤其在ext4文件系统没有加上data=ordered选项(redis宕机或者异常终止不会造成尾部不完整现象。)出现这种现象,可以选择让redis退出,或者导入尽可能多的数据。如果选择的是yes,当截断的aof文件被导入的时候,会自动发布一个log给客户端然后load。如果是no,用户必须手动redis-check-aof修复AOF文件才可以。 193aof-load-truncated yes 194 195################################ LUA SCRIPTING ############################### 196# 如果达到最大时间限制(毫秒),redis会记个log,然后返回error。当一个脚本超过了最大时限。只有SCRIPT KILLSHUTDOWN NOSAVE可以用。第一个可以杀没有调write命令的东西。要是已经调用了write,只能用第二个命令杀。 197lua-time-limit 5000 198 199################################ REDIS CLUSTER ############################### 200#集群开关,默认是不开启集群模式。 201# cluster-enabled yes 202 203#集群配置文件的名称,每个节点都有一个集群相关的配置文件,持久化保存集群的信息。这个文件并不需要手动配置,这个配置文件有Redis生成并更新,每个Redis集群节点需要一个单独的配置文件,请确保与实例运行的系统中配置文件名称不冲突 204# cluster-config-file nodes-6379.conf 205 206#节点互连超时的阀值。集群节点超时毫秒数 207# cluster-node-timeout 15000 208 209#在进行故障转移的时候,全部slave都会请求申请为master,但是有些slave可能与master断开连接一段时间了,导致数据过于陈旧,这样的slave不应该被提升为master。该参数就是用来判断slave节点与master断线的时间是否过长。判断方法是: 210#比较slave断开连接的时间和(node-timeout * slave-validity-factor) + repl-ping-slave-period 211#如果节点超时时间为三十秒, 并且slave-validity-factor为10,假设默认的repl-ping-slave-period是10秒,即如果超过310秒slave将不会尝试进行故障转移 212# cluster-slave-validity-factor 10 213 214#master的slave数量大于该值,slave才能迁移到其他孤立master上,如这个参数若被设为2,那么只有当一个主节点拥有2 个可工作的从节点时,它的一个从节点会尝试迁移。 215# cluster-migration-barrier 1 216 217#默认情况下,集群全部的slot有节点负责,集群状态才为ok,才能提供服务。设置为no,可以在slot没有全部分配的时候提供服务。不建议打开该配置,这样会造成分区的时候,小分区的master一直在接受写请求,而造成很长时间数据不一致。 218# cluster-require-full-coverage yes 219 220################################## SLOW LOG ################################### 221###slog log是用来记录redis运行中执行比较慢的命令耗时。当命令的执行超过了指定时间,就记录在slow log中,slog log保存在内存中,所以没有IO操作。 222#执行时间比slowlog-log-slower-than大的请求记录到slowlog里面,单位是微秒,所以1000000就是1秒。注意,负数时间会禁用慢查询日志,而0则会强制记录所有命令。 223slowlog-log-slower-than 10000 224 225#慢查询日志长度。当一个新的命令被写进日志的时候,最老的那个记录会被删掉。这个长度没有限制。只要有足够的内存就行。你可以通过 SLOWLOG RESET 来释放内存。 226slowlog-max-len 128 227 228################################ LATENCY MONITOR ############################## 229#延迟监控功能是用来监控redis中执行比较缓慢的一些操作,用LATENCY打印redis实例在跑命令时的耗时图表。只记录大于等于下边设置的值的操作。0的话,就是关闭监视。默认延迟监控功能是关闭的,如果你需要打开,也可以通过CONFIG SET命令动态设置。 230latency-monitor-threshold 0 231 232############################# EVENT NOTIFICATION ############################## 233#键空间通知使得客户端可以通过订阅频道或模式,来接收那些以某种方式改动了 Redis 数据集的事件。因为开启键空间通知功能需要消耗一些 CPU ,所以在默认配置下,该功能处于关闭状态。 234#notify-keyspace-events 的参数可以是以下字符的任意组合,它指定了服务器该发送哪些类型的通知: 235##K 键空间通知,所有通知以 __keyspace@__ 为前缀 236##E 键事件通知,所有通知以 __keyevent@__ 为前缀 237##g DELEXPIRERENAME 等类型无关的通用命令的通知 238##$ 字符串命令的通知 239##l 列表命令的通知 240##s 集合命令的通知 241##h 哈希命令的通知 242##z 有序集合命令的通知 243##x 过期事件:每当有过期键被删除时发送 244##e 驱逐(evict)事件:每当有键因为 maxmemory 政策而被删除时发送 245##A 参数 g$lshzxe 的别名 246#输入的参数中至少要有一个 K 或者 E,否则的话,不管其余的参数是什么,都不会有任何 通知被分发。详细使用可以参考http://redis.io/topics/notifications 247 248notify-keyspace-events "" 249 250############################### ADVANCED CONFIG ############################### 251#数据量小于等于hash-max-ziplist-entries的用ziplist,大于hash-max-ziplist-entries用hash 252hash-max-ziplist-entries 512 253#value大小小于等于hash-max-ziplist-value的用ziplist,大于hash-max-ziplist-value用hash。 254hash-max-ziplist-value 64 255 256#数据量小于等于list-max-ziplist-entries用ziplist,大于list-max-ziplist-entries用list。 257list-max-ziplist-entries 512 258#value大小小于等于list-max-ziplist-value的用ziplist,大于list-max-ziplist-value用list。 259list-max-ziplist-value 64 260 261#数据量小于等于set-max-intset-entries用iniset,大于set-max-intset-entries用set262set-max-intset-entries 512 263 264#数据量小于等于zset-max-ziplist-entries用ziplist,大于zset-max-ziplist-entries用zset。 265zset-max-ziplist-entries 128 266#value大小小于等于zset-max-ziplist-value用ziplist,大于zset-max-ziplist-value用zset。 267zset-max-ziplist-value 64 268 269#value大小小于等于hll-sparse-max-bytes使用稀疏数据结构(sparse),大于hll-sparse-max-bytes使用稠密的数据结构(dense)。一个比16000大的value是几乎没用的,建议的value大概为3000。如果对CPU要求不高,对空间要求较高的,建议设置到10000左右。 270hll-sparse-max-bytes 3000 271 272#Redis将在每100毫秒时使用1毫秒的CPU时间来对redis的hash表进行重新hash,可以降低内存的使用。当你的使用场景中,有非常严格的实时性需要,不能够接受Redis时不时的对请求有2毫秒的延迟的话,把这项配置为no。如果没有这么严格的实时性要求,可以设置为yes,以便能够尽可能快的释放内存。 273activerehashing yes 274 275##对客户端输出缓冲进行限制可以强迫那些不从服务器读取数据的客户端断开连接,用来强制关闭传输缓慢的客户端。 276#对于normal client,第一个0表示取消hard limit,第二个0和第三个0表示取消soft limit,normal client默认取消限制,因为如果没有寻问,他们是不会接收数据的。 277client-output-buffer-limit normal 0 0 0 278#对于slave client和MONITER client,如果client-output-buffer一旦超过256mb,又或者超过64mb持续60秒,那么服务器就会立即断开客户端连接。 279client-output-buffer-limit slave 256mb 64mb 60 280#对于pubsub client,如果client-output-buffer一旦超过32mb,又或者超过8mb持续60秒,那么服务器就会立即断开客户端连接。 281client-output-buffer-limit pubsub 32mb 8mb 60 282 283#redis执行任务的频率为1s除以hz。 284hz 10 285 286#在aof重写的时候,如果打开了aof-rewrite-incremental-fsync开关,系统会每32MB执行一次fsync。这对于把文件写入磁盘是有帮助的,可以避免过大的延迟峰值。 287aof-rewrite-incremental-fsync yes 288———————————————— 289版权声明:本文为CSDN博主「aijou_karen」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 290原文链接:https://blog.csdn.net/digimon100/article/details/92403763

 原文翻译,转自:https://www.cnblogs.com/wuzhenzhao/p/9578981.html

1# Redis configuration file example. 2# 3# Note that in order to read the configuration file, Redis must be 4# started with the file path as first argument: 5# 6# ./redis-server /path/to/redis.conf 7# Note on units: when memory size is needed, it is possible to specify 8# it in the usual form of 1k 5GB 4M and so forth: 9# 10# 1k => 1000 bytes 11# 1kb => 1024 bytes 12# 1m => 1000000 bytes 13# 1mb => 1024*1024 bytes 14# 1g => 1000000000 bytes 15# 1gb => 1024*1024*1024 bytes 16# 17# units are case insensitive so 1GB 1Gb 1gB are all the same. 18################################## INCLUDES ################################# 19# Include one or more other config files here. This is useful if you 20# have a standard template that goes to all Redis servers but also need 21# to customize a few per-server settings. Include files can include 22# other files, so use this wisely. 23# 24# Notice option "include" won't be rewritten by command "CONFIG REWRITE" 25# from admin or Redis Sentinel. Since Redis always uses the last processed 26# line as value of a configuration directive, you'd better put includes 27# at the beginning of this file to avoid overwriting config change at runtime. 28# 29# If instead you are interested in using includes to override configuration 30# options, it is better to use include as the last line. 31 32# 在这里包括一个或多个配置文件。这很有用#有一个标准的模板,适用于所有Redis服务器, 33#但也需要为每个服务器定制一些设置。包含文件可以包括#其他文件,所以要明智地使用它。 34#通知选项“include”不会被命令“CONFIG REWRITE”重写,来自admin或Redis Sentinel。 35#因为Redis总是使用最后处理过的作为配置指令的值,你最好输入include在此文件的开头 36#以避免在运行时覆盖配置更改。 37#如果您感兴趣的是使用include覆盖配置,options最好使用include作为最后一行。 38# include /path/to/local.conf 39# include /path/to/other.conf 40################################## MODULES ##################################### 41# Load modules at startup. If the server is not able to load modules 42# it will abort. It is possible to use multiple loadmodule directives. 43# 在启动时加载模块。如果服务器不能加载模块#将中止。可以使用多个loadmodule指令。 44# loadmodule /path/to/my_module.so 45# loadmodule /path/to/other_module.so 46################################## NETWORK ##################################### 47# By default, if no "bind" configuration directive is specified, Redis listens 48# for connections from all the network interfaces available on the server. 49# It is possible to listen to just one or multiple selected interfaces using 50# the "bind" configuration directive, followed by one or more IP addresses. 51# 52# 默认情况下,redis 在 server 上所有有效的网络接口上监听客户端连接。 53# 你如果只想让它在一个网络接口上监听,那你就绑定一个IP或者多个IP54# 55# 示例,多个IP用空格隔开: 56# Examples: 57# 58# bind 192.168.1.100 10.0.0.1 59# bind 127.0.0.1 ::1 60# 61# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the 62# internet, binding to all the interfaces is dangerous and will expose the 63# instance to everybody on the internet. So by default we uncomment the 64# following bind directive, that will force Redis to listen only into 65# the IPv4 lookback interface address (this means Redis will be able to 66# accept connections only from clients running into the same computer it 67# is running). 68# 69# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES 70# JUST COMMENT THE FOLLOWING LINE. 71# 如果您确定希望实例监听所有接口只需注释下面的行。 72# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73# bind 127.0.0.1 74# Protected mode is a layer of security protection, in order to avoid that 75# Redis instances left open on the internet are accessed and exploited. 76# 77# When protected mode is on and if: 78# 79# 1) The server is not binding explicitly to a set of addresses using the 80# "bind" directive. 81# 2) No password is configured. 82# 83# The server only accepts connections from clients connecting from the 84# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain 85# sockets. 86# 87# By default protected mode is enabled. You should disable it only if 88# you are sure you want clients from other hosts to connect to Redis 89# even if no authentication is configured, nor a specific set of interfaces 90# are explicitly listed using the "bind" directive. 91#是否开启保护模式,默认开启。要是配置里没有指定bind和密码。 92#开启该参数后,redis只会本地进行访问,拒绝外部访问。要是开启了密码和bind,可以开启。 93#否则最好关闭,设置为no。 94protected-mode yes 95 96# Accept connections on the specified port, default is 6379 (IANA #815344). 97# If port 0 is specified Redis will not listen on a TCP socket. 98# 端口号 99port 6399 100 101# TCP listen() backlog. 102# 103# In high requests-per-second environments you need an high backlog in order 104# to avoid slow clients connections issues. Note that the Linux kernel 105# will silently truncate it to the value of /proc/sys/net/core/somaxconn so 106# make sure to raise both the value of somaxconn and tcp_max_syn_backlog 107# in order to get the desired effect. 108 109此参数确定了TCP连接中已完成队列(完成三次握手之后)的长度, 110当然此值必须不大于Linux系统定义的/proc/sys/net/core/somaxconn值,默认是511111而Linux的默认参数值是128。当系统并发量大并且客户端速度缓慢的时候, 112可以将这二个参数一起参考设定。该内核参数默认值一般是128113对于负载很大的服务程序来说大大的不够。一般会将它修改为2048或者更大。 114/etc/sysctl.conf中添加:net.core.somaxconn = 2048,然后在终端中执行sysctl -p。 115 116tcp-backlog 511 117 118# Unix socket. 119# 120# Specify the path for the Unix socket that will be used to listen for 121# incoming connections. There is no default, so Redis will not listen 122# on a unix socket when not specified. 123#指定 unix socket 的路径。 124# unixsocket /tmp/redis.sock 125# unixsocketperm 700 126# Close the connection after a client is idle for N seconds (0 to disable) 127指定在一个 client 空闲多少秒之后关闭连接(0 就是不管它) 128timeout 0 129# TCP keepalive. 130# 131# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence 132# of communication. This is useful for two reasons: 133# 134# tcp 心跳包。 135# 136# 如果设置为非零,则在与客户端缺乏通讯的时候使用 SO_KEEPALIVE 发送 tcp acks 给客户端。 137# 1) Detect dead peers. 138# 2) Take the connection alive from the point of view of network 139# equipment in the middle. 140# 141# On Linux, the specified value (in seconds) is the period used to send ACKs. 142# Note that to close the connection the double of the time is needed. 143# On other kernels the period depends on the kernel configuration. 144# 145# A reasonable value for this option is 300 seconds, which is the new 146# Redis default starting with Redis 3.2.1. 147这个选项的合理值是300秒,这是新的# Redis默认从Redis 3.2.1开始。 148tcp-keepalive 300 149################################# GENERAL ##################################### 150# By default Redis does not run as a daemon. Use 'yes' if you need it. 151# Note that Redis will write a pid file in /var/run/redis.pid when daemonized. 152默认情况下 redis 不是作为守护进程运行的,如果你想让它在后台运行,你就把它改成 yes。 153daemonize yes 154# If you run Redis from upstart or systemd, Redis can interact with your 155# supervision tree. Options: 156# supervised no - no supervision interaction 157# supervised upstart - signal upstart by putting Redis into SIGSTOP mode 158# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET 159# supervised auto - detect upstart or systemd method based on 160# UPSTART_JOB or NOTIFY_SOCKET environment variables 161# Note: these supervision methods only signal "process is ready." 162# They do not enable continuous liveness pings back to your supervisor. 163可以通过upstart和systemd管理Redis守护进程,这个参数是和具体的操作系统相关的。 164supervised no 165# If a pid file is specified, Redis writes it where specified at startup 166# and removes it at exit. 167# 168# When the server runs non daemonized, no pid file is created if none is 169# specified in the configuration. When the server is daemonized, the pid file 170# is used even if not specified, defaulting to "/var/run/redis.pid". 171# 172# Creating a pid file is best effort: if Redis is not able to create it 173# nothing bad happens, the server will start and run normally. 174# 当redis作为守护进程运行的时候,它会把 pid 默认写到 /var/run/redis.pid 文件里面, 175# 但是你可以在这里自己制定它的文件位置。 176pidfile /var/run/redis_6379.pid 177# Specify the server verbosity level. 178# This can be one of: 179# debug (a lot of information, useful for development/testing) 180# verbose (many rarely useful info, but not a mess like the debug level) 181# notice (moderately verbose, what you want in production probably) 182# warning (only very important / critical messages are logged) 183# 定义日志级别。 184# 可以是下面的这些值: 185# debug (适用于开发或测试阶段) 186# verbose (many rarely useful info, but not a mess like the debug level) 187# notice (适用于生产环境) 188# warning (仅仅一些重要的消息被记录) 189loglevel notice 190# Specify the log file name. Also the empty string can be used to force 191# Redis to log on the standard output. Note that if you use standard 192# output for logging but daemonize, logs will be sent to /dev/null 193指定日志文件的位置 194logfile "" 195# To enable logging to the system logger, just set 'syslog-enabled' to yes, 196# and optionally update the other syslog parameters to suit your needs. 197# syslog-enabled no 198# Specify the syslog identity. 199# syslog-ident redis 200# Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7. 201# syslog-facility local0 202# Set the number of databases. The default database is DB 0, you can select 203# a different one on a per-connection basis using SELECT <dbid> where 204# dbid is a number between 0 and 'databases'-1 205# 设置数据库的数目。 206# 默认数据库是 DB 0,你可以在每个连接上使用 select <dbid> 命令选择一个不同的数据库, 207# 但是 dbid 必须是一个介于 0 到 databasees - 1 之间的值 208databases 16 209# By default Redis shows an ASCII art logo only when started to log to the 210# standard output and if the standard output is a TTY. Basically this means 211# that normally a logo is displayed only in interactive sessions. 212# 213# However it is possible to force the pre-4.0 behavior and always show a 214# ASCII art logo in startup logs by setting the following option to yes. 215默认情况下,Redis只在开始登录时才显示ASCII艺术标志标准输出,如果标准输出是TTY216基本上这意味着通常标识只在交互会话中显示。#然而,强迫4.0之前的行为并总是显示a是 217可能的# ASCII艺术标志在启动日志通过设置下列选项是 218always-show-logo yes 219################################ SNAPSHOTTING ################################ 220# 221# Save the DB on disk: 222# 223# save <seconds> <changes> 224# 225# Will save the DB if both the given number of seconds and the given 226# number of write operations against the DB occurred. 227# 228# In the example below the behaviour will be to save: 229# after 900 sec (15 min) if at least 1 key changed 230# after 300 sec (5 min) if at least 10 keys changed 231# after 60 sec if at least 10000 keys changed 232# 233# Note: you can disable saving completely by commenting out all "save" lines. 234# 235# It is also possible to remove all the previously configured save 236# points by adding a save directive with a single empty string argument 237# like in the following example: 238# 239# save "" 240# 存 DB 到磁盘: 241# 242# 格式:save <间隔时间(秒)> <写入次数> 243# 244# 根据给定的时间间隔和写入次数将数据保存到磁盘 245# 246# 下面的例子的意思是: 247# 900 秒内如果至少有 1 个 key 的值变化,则保存 248# 300 秒内如果至少有 10 个 key 的值变化,则保存 249# 60 秒内如果至少有 10000 个 key 的值变化,则保存 250#   251# 注意:你可以注释掉所有的 save 行来停用保存功能。 252# 也可以直接一个空字符串来实现停用: 253# save "" 254save 900 1 255save 300 10 256save 60 10000 257# By default Redis will stop accepting writes if RDB snapshots are enabled 258# (at least one save point) and the latest background save failed. 259# This will make the user aware (in a hard way) that data is not persisting 260# on disk properly, otherwise chances are that no one will notice and some 261# disaster will happen. 262# 263# If the background saving process will start working again Redis will 264# automatically allow writes again. 265# 266# However if you have setup your proper monitoring of the Redis server 267# and persistence, you may want to disable this feature so that Redis will 268# continue to work as usual even if there are problems with disk, 269# permissions, and so forth. 270# 默认情况下,如果 redis 最后一次的后台保存失败,redis 将停止接受写操作, 271# 这样以一种强硬的方式让用户知道数据不能正确的持久化到磁盘, 272# 否则就会没人注意到灾难的发生。 273# 274# 如果后台保存进程重新启动工作了,redis 也将自动的允许写操作。 275# 276# 然而你要是安装了靠谱的监控,你可能不希望 redis 这样做,那你就改成 no 好了。 277stop-writes-on-bgsave-error yes 278# Compress string objects using LZF when dump .rdb databases? 279# For default that's set to 'yes' as it's almost always a win. 280# If you want to save some CPU in the saving child set it to 'no' but 281# the dataset will likely be bigger if you have compressible values or keys. 282# 是否在 dump .rdb 数据库的时候使用 LZF 压缩字符串 283# 默认都设为 yes 284# 如果你希望保存子进程节省点 cpu ,你就设置它为 no , 285# 不过这个数据集可能就会比较大 286rdbcompression yes 287# Since version 5 of RDB a CRC64 checksum is placed at the end of the file. 288# This makes the format more resistant to corruption but there is a performance 289# hit to pay (around 10%) when saving and loading RDB files, so you can disable it 290# for maximum performances. 291# 292# RDB files created with checksum disabled have a checksum of zero that will 293# tell the loading code to skip the check. 294# 是否校验rdb文件 295rdbchecksum yes 296# The filename where to dump the DB 297# 设置 dump 的文件位置 298dbfilename dump.rdb 299# The working directory. 300# 301# The DB will be written inside this directory, with the filename specified 302# above using the 'dbfilename' configuration directive. 303# 304# The Append Only File will also be created inside this directory. 305# 306# Note that you must specify a directory here, not a file name. 307# 工作目录 308# 例如上面的 dbfilename 只指定了文件名, 309# 但是它会写入到这个目录下。这个配置项一定是个目录,而不能是文件名。 310dir ./ 311################################# REPLICATION ################################# 312# Master-Slave replication. Use slaveof to make a Redis instance a copy of 313# another Redis server. A few things to understand ASAP about Redis replication. 314# 315# 1) Redis replication is asynchronous, but you can configure a master to 316# stop accepting writes if it appears to be not connected with at least 317# a given number of slaves. 318# 2) Redis slaves are able to perform a partial resynchronization with the 319# master if the replication link is lost for a relatively small amount of 320# time. You may want to configure the replication backlog size (see the next 321# sections of this file) with a sensible value depending on your needs. 322# 3) Replication is automatic and does not need user intervention. After a 323# network partition slaves automatically try to reconnect to masters 324# and resynchronize with them. 325# 326# slaveof <masterip> <masterport> 327# If the master is password protected (using the "requirepass" configuration 328# directive below) it is possible to tell the slave to authenticate before 329# starting the replication synchronization process, otherwise the master will 330# refuse the slave request. 331# 332# masterauth <master-password> 333# When a slave loses its connection with the master, or when the replication 334# is still in progress, the slave can act in two different ways: 335# 336# 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will 337# still reply to client requests, possibly with out of date data, or the 338# data set may just be empty if this is the first synchronization. 339# 340# 2) if slave-serve-stale-data is set to 'no' the slave will reply with 341# an error "SYNC with master in progress" to all the kind of commands 342# but to INFO and SLAVEOF. 343# 主从复制。使用 slaveof 来让一个 redis 实例成为另一个reids 实例的副本。 344# 注意这个只需要在 slave 上配置。 345# 346# slaveof <masterip> <masterport> 347 348# 如果 master 需要密码认证,就在这里设置 349# masterauth <master-password> 350 351# 当一个 slave 与 master 失去联系,或者复制正在进行的时候, 352# slave 可能会有两种表现: 353# 354# 1) 如果为 yes ,slave 仍然会应答客户端请求,但返回的数据可能是过时, 355# 或者数据可能是空的在第一次同步的时候 356# 357# 2) 如果为 no ,在你执行除了 info he salveof 之外的其他命令时, 358# slave 都将返回一个 "SYNC with master in progress" 的错误, 359# 360slave-serve-stale-data yes 361# You can configure a slave instance to accept writes or not. Writing against 362# a slave instance may be useful to store some ephemeral data (because data 363# written on a slave will be easily deleted after resync with the master) but 364# may also cause problems if clients are writing to it because of a 365# misconfiguration. 366# 367# Since Redis 2.6 by default slaves are read-only. 368# 369# Note: read only slaves are not designed to be exposed to untrusted clients 370# on the internet. It's just a protection layer against misuse of the instance. 371# Still a read only slave exports by default all the administrative commands 372# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve 373# security of read only slaves using 'rename-command' to shadow all the 374# administrative / dangerous commands. 375# 你可以配置一个 slave 实体是否接受写入操作。 376# 通过写入操作来存储一些短暂的数据对于一个 slave 实例来说可能是有用的, 377# 因为相对从 master 重新同步数而言,据数据写入到 slave 会更容易被删除。 378# 但是如果客户端因为一个错误的配置写入,也可能会导致一些问题。 379# 380# 从 redis 2.6 版起,默认 slaves 都是只读的。 381# 382# Note: read only slaves are not designed to be exposed to untrusted clients 383# on the internet. It's just a protection layer against misuse of the instance. 384# Still a read only slave exports by default all the administrative commands 385# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve 386# security of read only slaves using 'rename-command' to shadow all the 387# administrative / dangerous commands. 388# 注意:只读的 slaves 没有被设计成在 internet 上暴露给不受信任的客户端。 389# 它仅仅是一个针对误用实例的一个保护层。 390slave-read-only yes 391# Replication SYNC strategy: disk or socket. 392# 393# ------------------------------------------------------- 394# WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY 395# ------------------------------------------------------- 396# 397# New slaves and reconnecting slaves that are not able to continue the replication 398# process just receiving differences, need to do what is called a "full 399# synchronization". An RDB file is transmitted from the master to the slaves. 400# The transmission can happen in two different ways: 401# 402# 1) Disk-backed: The Redis master creates a new process that writes the RDB 403# file on disk. Later the file is transferred by the parent 404# process to the slaves incrementally. 405# 2) Diskless: The Redis master creates a new process that directly writes the 406# RDB file to slave sockets, without touching the disk at all. 407# 408# With disk-backed replication, while the RDB file is generated, more slaves 409# can be queued and served with the RDB file as soon as the current child producing 410# the RDB file finishes its work. With diskless replication instead once 411# the transfer starts, new slaves arriving will be queued and a new transfer 412# will start when the current one terminates. 413# 414# When diskless replication is used, the master waits a configurable amount of 415# time (in seconds) before starting the transfer in the hope that multiple slaves 416# will arrive and the transfer can be parallelized. 417# 418# With slow disks and fast (large bandwidth) networks, diskless replication 419# works better. 420#是否使用socket方式复制数据。目前redis复制提供两种方式,disk和socket。 421如果新的slave连上来或者重连的slave无法部分同步,就会执行全量同步,master会生成rdb文件。 4222种方式:disk方式是master创建一个新的进程把rdb文件保存到磁盘, 423再把磁盘上的rdb文件传递给slave。socket是master创建一个新的进程, 424直接把rdb文件以socket的方式发给slave。disk方式的时候,当一个rdb保存的过程中, 425多个slave都能共享这个rdb文件。socket的方式就的一个个slave顺序复制。在磁盘速度缓慢, 426网速快的情况下推荐用socket方式。 427repl-diskless-sync no 428# When diskless replication is enabled, it is possible to configure the delay 429# the server waits in order to spawn the child that transfers the RDB via socket 430# to the slaves. 431# 432# This is important since once the transfer starts, it is not possible to serve 433# new slaves arriving, that will be queued for the next RDB transfer, so the server 434# waits a delay in order to let more slaves arrive. 435# 436# The delay is specified in seconds, and by default is 5 seconds. To disable 437# it entirely just set it to 0 seconds and the transfer will start ASAP. 438#diskless复制的延迟时间,防止设置为0。一旦复制开始, 439节点不会再接收新slave的复制请求直到下一个rdb传输。所以最好等待一段时间,等更多的slave连上来。 440repl-diskless-sync-delay 5 441# Slaves send PINGs to server in a predefined interval. It's possible to change 442# this interval with the repl_ping_slave_period option. The default value is 10 443# seconds. 444# 445# Slaves 在一个预定义的时间间隔内发送 ping 命令到 server 。 446# 你可以改变这个时间间隔。默认为 10 秒。 447# repl-ping-slave-period 10 448# The following option sets the replication timeout for: 449# 450# 1) Bulk transfer I/O during SYNC, from the point of view of slave. 451# 2) Master timeout from the point of view of slaves (data, pings). 452# 3) Slave timeout from the point of view of masters (REPLCONF ACK pings). 453# 454# It is important to make sure that this value is greater than the value 455# specified for repl-ping-slave-period otherwise a timeout will be detected 456# every time there is low traffic between the master and the slave. 457# 458#复制连接超时时间。master和slave都有超时时间的设置。 459master检测到slave上次发送的时间超过repl-timeout,即认为slave离线,清除该slave信息。 460slave检测到上次和master交互的时间超过repl-timeout,则认为master离线。 461需要注意的是repl-timeout需要设置一个比repl-ping-slave-period更大的值,不然会经常检测到超时。 462# repl-timeout 60 463# Disable TCP_NODELAY on the slave socket after SYNC? 464# 465# If you select "yes" Redis will use a smaller number of TCP packets and 466# less bandwidth to send data to slaves. But this can add a delay for 467# the data to appear on the slave side, up to 40 milliseconds with 468# Linux kernels using a default configuration. 469# 470# If you select "no" the delay for data to appear on the slave side will 471# be reduced but more bandwidth will be used for replication. 472# 473# By default we optimize for low latency, but in very high traffic conditions 474# or when the master and slaves are many hops away, turning this to "yes" may 475# be a good idea. 476#是否禁止复制tcp链接的tcp nodelay参数,可传递yes或者no。默认是no, 477即使用tcp nodelay。如果master设置了yes来禁止tcp nodelay设置, 478在把数据复制给slave的时候,会减少包的数量和更小的网络带宽。 479但是这也可能带来数据的延迟。默认我们推荐更小的延迟, 480但是在数据量传输很大的场景下,建议选择yes。 481repl-disable-tcp-nodelay no 482# Set the replication backlog size. The backlog is a buffer that accumulates 483# slave data when slaves are disconnected for some time, so that when a slave 484# wants to reconnect again, often a full resync is not needed, but a partial 485# resync is enough, just passing the portion of data the slave missed while 486# disconnected. 487# 488# The bigger the replication backlog, the longer the time the slave can be 489# disconnected and later be able to perform a partial resynchronization. 490# 491# The backlog is only allocated once there is at least a slave connected. 492# 493#复制缓冲区大小,这是一个环形复制缓冲区,用来保存最新复制的命令。 494这样在slave离线的时候,不需要完全复制master的数据,如果可以执行部分同步, 495只需要把缓冲区的部分数据复制给slave,就能恢复正常复制状态。缓冲区的大小越大, 496slave离线的时间可以更长,复制缓冲区只有在有slave连接的时候才分配内存。 497没有slave的一段时间,内存会被释放出来,默认1m。 498# repl-backlog-size 1mb 499# After a master has no longer connected slaves for some time, the backlog 500# will be freed. The following option configures the amount of seconds that 501# need to elapse, starting from the time the last slave disconnected, for 502# the backlog buffer to be freed. 503# 504# Note that slaves never free the backlog for timeout, since they may be 505# promoted to masters later, and should be able to correctly "partially 506# resynchronize" with the slaves: hence they should always accumulate backlog. 507# 508# A value of 0 means to never release the backlog. 509# 510# master没有slave一段时间会释放复制缓冲区的内存, 511 repl-backlog-ttl用来设置该时间长度。单位为秒。 512 513# repl-backlog-ttl 3600 514# The slave priority is an integer number published by Redis in the INFO output. 515# It is used by Redis Sentinel in order to select a slave to promote into a 516# master if the master is no longer working correctly. 517# 518# A slave with a low priority number is considered better for promotion, so 519# for instance if there are three slaves with priority 10, 100, 25 Sentinel will 520# pick the one with priority 10, that is the lowest. 521# 522# However a special priority of 0 marks the slave as not able to perform the 523# role of master, so a slave with priority of 0 will never be selected by 524# Redis Sentinel for promotion. 525# 526# By default the priority is 100. 527当master不可用,Sentinel会根据slave的优先级选举一个master。 528最低的优先级的slave,当选master。而配置成0,永远不会被选举。 529slave-priority 100 530# It is possible for a master to stop accepting writes if there are less than 531# N slaves connected, having a lag less or equal than M seconds. 532# 533# The N slaves need to be in "online" state. 534# 535# The lag in seconds, that must be <= the specified value, is calculated from 536# the last ping received from the slave, that is usually sent every second. 537# 538# This option does not GUARANTEE that N replicas will accept the write, but 539# will limit the window of exposure for lost writes in case not enough slaves 540# are available, to the specified number of seconds. 541# 542# For example to require at least 3 slaves with a lag <= 10 seconds use: 543# 544#redis提供了可以让master停止写入的方式,如果配置了min-slaves-to-write, 545健康的slave的个数小于N,mater就禁止写入。master最少得有多少个健康的slave存活才能执行写命令。 546这个配置虽然不能保证N个slave都一定能接收到master的写操作,但是能避免没有足够健康的slave的时候, 547master不能写入来避免数据丢失。设置为0是关闭该功能。 548# min-slaves-to-write 3 549#延迟小于min-slaves-max-lag秒的slave才认为是健康的slave。 550# min-slaves-max-lag 10 551# 552# Setting one or the other to 0 disables the feature. 553# 554# By default min-slaves-to-write is set to 0 (feature disabled) and 555# min-slaves-max-lag is set to 10. 556# A Redis master is able to list the address and port of the attached 557# slaves in different ways. For example the "INFO replication" section 558# offers this information, which is used, among other tools, by 559# Redis Sentinel in order to discover slave instances. 560# Another place where this info is available is in the output of the 561# "ROLE" command of a master. 562# 563# The listed IP and address normally reported by a slave is obtained 564# in the following way: 565# 566# IP: The address is auto detected by checking the peer address 567# of the socket used by the slave to connect with the master. 568# 569# Port: The port is communicated by the slave during the replication 570# handshake, and is normally the port that the slave is using to 571# list for connections. 572# 573# However when port forwarding or Network Address Translation (NAT) is 574# used, the slave may be actually reachable via different IP and port 575# pairs. The following two options can be used by a slave in order to 576# report to its master a specific set of IP and port, so that both INFO 577# and ROLE will report those values. 578# 579# There is no need to use both the options if you need to override just 580# the port or the IP address. 581# 582 Redis master能够以不同的方式列出所连接slave的地址和端口。 583 例如,“INFO replication”部分提供此信息,除了其他工具之外,Redis Sentinel还使用该信息来发现slave实例。 584 此信息可用的另一个地方在masterser的“ROLE”命令的输出中。 585 通常由slave报告的列出的IP和地址,通过以下方式获得: 586 IP:通过检查slave与master连接使用的套接字的对等体地址自动检测地址。 587 端口:端口在复制握手期间由slavet通信,并且通常是slave正在使用列出连接的端口。 588 然而,当使用端口转发或网络地址转换(NAT)时,slave实际上可以通过(不同的IP和端口对)来到达。 589 slave可以使用以下两个选项,以便向master报告一组特定的IP和端口, 590 以便INFOROLE将报告这些值。 591 如果你需要仅覆盖端口或IP地址,则没必要使用这两个选项。 592# slave-announce-ip 5.5.5.5 593# slave-announce-port 1234 594################################## SECURITY ################################### 595# Require clients to issue AUTH <PASSWORD> before processing any other 596# commands. This might be useful in environments in which you do not trust 597# others with access to the host running redis-server. 598# 599# This should stay commented out for backward compatibility and because most 600# people do not need auth (e.g. they run their own servers). 601# 602# Warning: since Redis is pretty fast an outside user can try up to 603# 150k passwords per second against a good box. This means that you should 604# use a very strong password otherwise it will be very easy to break. 605# 606# 设置认证密码 607 requirepass password 608# Command renaming. 609# 610# It is possible to change the name of dangerous commands in a shared 611# environment. For instance the CONFIG command may be renamed into something 612# hard to guess so that it will still be available for internal-use tools 613# but not available for general clients. 614# 615# Example: 616# 617# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 618# 619# It is also possible to completely kill a command by renaming it into 620# an empty string: 621# 622# rename-command CONFIG "" 623# 624# Please note that changing the name of commands that are logged into the 625# AOF file or transmitted to slaves may cause problems. 626################################### CLIENTS #################################### 627# Set the max number of connected clients at the same time. By default 628# this limit is set to 10000 clients, however if the Redis server is not 629# able to configure the process file limit to allow for the specified limit 630# the max number of allowed clients is set to the current file limit 631# minus 32 (as Redis reserves a few file descriptors for internal uses). 632# 633# Once the limit is reached Redis will close all the new connections sending 634# an error 'max number of clients reached'. 635# 636# 一旦达到最大限制,redis 将关闭所有的新连接 637# 并发送一个‘max number of clients reached’的错误。 638# maxclients 10000 639############################## MEMORY MANAGEMENT ################################ 640# Set a memory usage limit to the specified amount of bytes. 641# When the memory limit is reached Redis will try to remove keys 642# according to the eviction policy selected (see maxmemory-policy). 643# 644# If Redis can't remove keys according to the policy, or if the policy is 645# set to 'noeviction', Redis will start to reply with errors to commands 646# that would use more memory, like SET, LPUSH, and so on, and will continue 647# to reply to read-only commands like GET. 648# 649# This option is usually useful when using Redis as an LRU or LFU cache, or to 650# set a hard memory limit for an instance (using the 'noeviction' policy). 651# 652# WARNING: If you have slaves attached to an instance with maxmemory on, 653# the size of the output buffers needed to feed the slaves are subtracted 654# from the used memory count, so that network problems / resyncs will 655# not trigger a loop where keys are evicted, and in turn the output 656# buffer of slaves is full with DELs of keys evicted triggering the deletion 657# of more keys, and so forth until the database is completely emptied. 658# 659# In short... if you have slaves attached it is suggested that you set a lower 660# limit for maxmemory so that there is some free RAM on the system for slave 661# output buffers (but this is not needed if the policy is 'noeviction'). 662# 663# 最大使用内存 664# maxmemory <bytes> 665# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory 666# is reached. You can select among five behaviors: 667# 668# volatile-lru -> Evict using approximated LRU among the keys with an expire set. 669# allkeys-lru -> Evict any key using approximated LRU. 670# volatile-lfu -> Evict using approximated LFU among the keys with an expire set. 671# allkeys-lfu -> Evict any key using approximated LFU. 672# volatile-random -> Remove a random key among the ones with an expire set. 673# allkeys-random -> Remove a random key, any key. 674# volatile-ttl -> Remove the key with the nearest expire time (minor TTL) 675# noeviction -> Don't evict anything, just return an error on write operations. 676# 677# 最大内存策略,你有 5 个选择。 678# 679# volatile-lru -> remove the key with an expire set using an LRU algorithm 680# volatile-lru -> 使用 LRU 算法移除包含过期设置的 key 。 681# allkeys-lru -> remove any key accordingly to the LRU algorithm 682# allkeys-lru -> 根据 LRU 算法移除所有的 key 。 683# volatile-random -> remove a random key with an expire set 684# allkeys-random -> remove a random key, any key 685# volatile-ttl -> remove the key with the nearest expire time (minor TTL) 686# noeviction -> don't expire at all, just return an error on write operations 687# noeviction -> 不让任何 key 过期,只是给写入操作返回一个错误 688# LRU means Least Recently Used 689# LFU means Least Frequently Used 690# 691# Both LRU, LFU and volatile-ttl are implemented using approximated 692# randomized algorithms. 693# 694# Note: with any of the above policies, Redis will return an error on write 695# operations, when there are no suitable keys for eviction. 696# 697# At the date of writing these commands are: set setnx setex append 698# incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd 699# sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby 700# zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby 701# getset mset msetnx exec sort 702# 703# The default is: 704# 705LRU的意思是最近最少使用LFU的意思是最不常用的#使用近似方法实现了LRULFU和volatile-ttl#随机算法。 706#注意:对于上述任何一种策略,Redis都会在写入时返回一个错误操作,当没有合适的键被驱逐时。 707#在写这些命令的时候,设置setnx setex append地址:rpush lpush rpushx lpushx linsert lset rpoplpush 708sadd烧结商店sunion sunionstore sdiff sdiffstore zadd zincrbyzunionstore zinterstore hset 709 hsetnx hmset hincrby incrby decrby# getset mset msetnx exec排序 710##默认是: 711# maxmemory-policy noeviction 712# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated 713# algorithms (in order to save memory), so you can tune it for speed or 714# accuracy. For default Redis will check five keys and pick the one that was 715# used less recently, you can change the sample size using the following 716# configuration directive. 717# 718# The default of 5 produces good enough results. 10 Approximates very closely 719# true LRU but costs more CPU. 3 is faster but not very accurate. 720# 721LRULFU和最小TTL算法不是精确的算法,而是近似的#算法(为了节省内存)722所以您可以调整它的速度或#准确性。对于默认的Redis,会检查5个键并选择原来的键#最近使用的较少, 723您可以使用以下方法更改样本量#配置指令。#5的默认值产生足够好的结果。 72410密切接近真正的LRU,但需要更多的CPU3更快,但不是很准确。 725# maxmemory-samples 5 726############################# LAZY FREEING #################################### 727# Redis has two primitives to delete keys. One is called DEL and is a blocking 728# deletion of the object. It means that the server stops processing new commands 729# in order to reclaim all the memory associated with an object in a synchronous 730# way. If the key deleted is associated with a small object, the time needed 731# in order to execute the DEL command is very small and comparable to most other 732# O(1) or O(log_N) commands in Redis. However if the key is associated with an 733# aggregated value containing millions of elements, the server can block for 734# a long time (even seconds) in order to complete the operation. 735# 736# For the above reasons Redis also offers non blocking deletion primitives 737# such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and 738# FLUSHDB commands, in order to reclaim memory in background. Those commands 739# are executed in constant time. Another thread will incrementally free the 740# object in the background as fast as possible. 741# 742# DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled. 743# It's up to the design of the application to understand when it is a good 744# idea to use one or the other. However the Redis server sometimes has to 745# delete keys or flush the whole database as a side effect of other operations. 746# Specifically Redis deletes objects independently of a user call in the 747# following scenarios: 748# 749# 1) On eviction, because of the maxmemory and maxmemory policy configurations, 750# in order to make room for new data, without going over the specified 751# memory limit. 752# 2) Because of expire: when a key with an associated time to live (see the 753# EXPIRE command) must be deleted from memory. 754# 3) Because of a side effect of a command that stores data on a key that may 755# already exist. For example the RENAME command may delete the old key 756# content when it is replaced with another one. Similarly SUNIONSTORE 757# or SORT with STORE option may delete existing keys. The SET command 758# itself removes any old content of the specified key in order to replace 759# it with the specified string. 760# 4) During replication, when a slave performs a full resynchronization with 761# its master, the content of the whole database is removed in order to 762# load the RDB file just transfered. 763# 764# In all the above cases the default is to delete objects in a blocking way, 765# like if DEL was called. However you can configure each case specifically 766# in order to instead release memory in a non-blocking way like if UNLINK 767# was called, using the following configuration directives: 768lazy free可译为惰性删除或延迟释放;当删除键的时候,redis提供异步延时释放key内存的功能, 769把key释放操作放在bio(Background I/O)单独的子线程处理中,减少删除big key对redis主线程的阻塞。 770有效地避免删除big key带来的性能和可用性问题 771lazyfree-lazy-eviction no 772lazyfree-lazy-expire no 773lazyfree-lazy-server-del no 774slave-lazy-flush no 775############################## APPEND ONLY MODE ############################### 776# By default Redis asynchronously dumps the dataset on disk. This mode is 777# good enough in many applications, but an issue with the Redis process or 778# a power outage may result into a few minutes of writes lost (depending on 779# the configured save points). 780# 781# The Append Only File is an alternative persistence mode that provides 782# much better durability. For instance using the default data fsync policy 783# (see later in the config file) Redis can lose just one second of writes in a 784# dramatic event like a server power outage, or a single write if something 785# wrong with the Redis process itself happens, but the operating system is 786# still running correctly. 787# 788# AOF and RDB persistence can be enabled at the same time without problems. 789# If the AOF is enabled on startup Redis will load the AOF, that is the file 790# with the better durability guarantees. 791# 792# Please check http://redis.io/topics/persistence for more information. 793#默认redis使用的是rdb方式持久化,这种方式在许多应用中已经足够用了。 794但是redis如果中途宕机,会导致可能有几分钟的数据丢失,根据save来策略进行持久化, 795Append Only File是另一种持久化方式,可以提供更好的持久化特性。 796Redis会把每次写入的数据在接收后都写入 appendonly.aof 文件, 797每次启动时Redis都会先把这个文件的数据读入内存里,先忽略RDB文件。 798appendonly no 799# The name of the append only file (default: "appendonly.aof") 800#aof文件名 801appendfilename "appendonly.aof" 802# The fsync() call tells the Operating System to actually write data on disk 803# instead of waiting for more data in the output buffer. Some OS will really flush 804# data on disk, some other OS will just try to do it ASAP. 805# 806# Redis supports three different modes: 807# 808# no: don't fsync, just let the OS flush the data when it wants. Faster. 809# always: fsync after every write to the append only log. Slow, Safest. 810# everysec: fsync only one time every second. Compromise. 811# 812# The default is "everysec", as that's usually the right compromise between 813# speed and data safety. It's up to you to understand if you can relax this to 814# "no" that will let the operating system flush the output buffer when 815# it wants, for better performances (but if you can live with the idea of 816# some data loss consider the default persistence mode that's snapshotting), 817# or on the contrary, use "always" that's very slow but a bit safer than 818# everysec. 819# 820# More details please check the following article: 821# http://antirez.com/post/redis-persistence-demystified.html 822# 823# If unsure, use "everysec". 824# appendfsync always 825#aof持久化策略的配置 826#no表示不执行fsync,由操作系统保证数据同步到磁盘,速度最快。 827#always表示每次写入都执行fsync,以保证数据同步到磁盘。 828#everysec表示每秒执行一次fsync,可能会导致丢失这1s数据。 829appendfsync everysec 830# appendfsync no 831# When the AOF fsync policy is set to always or everysec, and a background 832# saving process (a background save or AOF log background rewriting) is 833# performing a lot of I/O against the disk, in some Linux configurations 834# Redis may block too long on the fsync() call. Note that there is no fix for 835# this currently, as even performing fsync in a different thread will block 836# our synchronous write(2) call. 837# 838# In order to mitigate this problem it's possible to use the following option 839# that will prevent fsync() from being called in the main process while a 840# BGSAVE or BGREWRITEAOF is in progress. 841# 842# This means that while another child is saving, the durability of Redis is 843# the same as "appendfsync none". In practical terms, this means that it is 844# possible to lose up to 30 seconds of log in the worst scenario (with the 845# default Linux settings). 846# 847# If you have latency problems turn this to "yes". Otherwise leave it as 848# "no" that is the safest pick from the point of view of durability. 849# 在aof重写或者写入rdb文件的时候,会执行大量IO,此时对于everysec和always的aof模式来说, 850执行fsync会造成阻塞过长时间,no-appendfsync-on-rewrite字段设置为默认设置为no。 851如果对延迟要求很高的应用,这个字段可以设置为yes,否则还是设置为no, 852这样对持久化特性来说这是更安全的选择。设置为yes表示rewrite期间对新写操作不fsync, 853暂时存在内存中,等rewrite完成后再写入,默认为no,建议yes。Linux的默认fsync策略是30秒。 854可能丢失30秒数据。 855no-appendfsync-on-rewrite no 856# Automatic rewrite of the append only file. 857# Redis is able to automatically rewrite the log file implicitly calling 858# BGREWRITEAOF when the AOF log size grows by the specified percentage. 859# 860# This is how it works: Redis remembers the size of the AOF file after the 861# latest rewrite (if no rewrite has happened since the restart, the size of 862# the AOF at startup is used). 863# 864# This base size is compared to the current size. If the current size is 865# bigger than the specified percentage, the rewrite is triggered. Also 866# you need to specify a minimal size for the AOF file to be rewritten, this 867# is useful to avoid rewriting the AOF file even if the percentage increase 868# is reached but it is still pretty small. 869# 870# Specify a percentage of zero in order to disable the automatic AOF 871# rewrite feature. 872#aof自动重写配置。当目前aof文件大小超过上一次重写的aof文件大小的百分之多少进行重写, 873即当aof文件增长到一定大小的时候Redis能够调用bgrewriteaof对日志文件进行重写。 874当前AOF文件大小是上次日志重写得到AOF文件大小的二倍(设置为100)时, 875自动启动新的日志重写过程。 876auto-aof-rewrite-percentage 100 877#设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写 878auto-aof-rewrite-min-size 64mb 879# An AOF file may be found to be truncated at the end during the Redis 880# startup process, when the AOF data gets loaded back into memory. 881# This may happen when the system where Redis is running 882# crashes, especially when an ext4 filesystem is mounted without the 883# data=ordered option (however this can't happen when Redis itself 884# crashes or aborts but the operating system still works correctly). 885# 886# Redis can either exit with an error when this happens, or load as much 887# data as possible (the default now) and start if the AOF file is found 888# to be truncated at the end. The following option controls this behavior. 889# 890# If aof-load-truncated is set to yes, a truncated AOF file is loaded and 891# the Redis server starts emitting a log to inform the user of the event. 892# Otherwise if the option is set to no, the server aborts with an error 893# and refuses to start. When the option is set to no, the user requires 894# to fix the AOF file using the "redis-check-aof" utility before to restart 895# the server. 896# 897# Note that if the AOF file will be found to be corrupted in the middle 898# the server will still exit with an error. This option only applies when 899# Redis will try to read more data from the AOF file but not enough bytes 900# will be found. 901#aof文件可能在尾部是不完整的,当redis启动的时候,aof文件的数据被载入内存。 902重启可能发生在redis所在的主机操作系统宕机后, 903尤其在ext4文件系统没有加上data=ordered选项(redis宕机或者异常终止不会造成尾部不完整现象。) 904出现这种现象,可以选择让redis退出,或者导入尽可能多的数据。如果选择的是yes, 905当截断的aof文件被导入的时候,会自动发布一个log给客户端然后load。如果是no, 906用户必须手动redis-check-aof修复AOF文件才可以。 907aof-load-truncated yes 908# When rewriting the AOF file, Redis is able to use an RDB preamble in the 909# AOF file for faster rewrites and recoveries. When this option is turned 910# on the rewritten AOF file is composed of two different stanzas: 911# 912# [RDB file][AOF tail] 913# 914# When loading Redis recognizes that the AOF file starts with the "REDIS" 915# string and loads the prefixed RDB file, and continues loading the AOF 916# tail. 917# 918# This is currently turned off by default in order to avoid the surprise 919# of a format change, but will at some point be used as the default. 920#Redis4.0新增RDB-AOF混合持久化格式,在开启了这个功能之后, 921AOF重写产生的文件将同时包含RDB格式的内容和AOF格式的内容, 922其中RDB格式的内容用于记录已有的数据,而AOF格式的内存则用于记录最近发生了变化的数据, 923这样Redis就可以同时兼有RDB持久化和AOF持久化的优点(既能够快速地生成重写文件, 924也能够在出现问题时,快速地载入数据)。 925aof-use-rdb-preamble no 926################################ LUA SCRIPTING ############################### 927# Max execution time of a Lua script in milliseconds. 928# 929# If the maximum execution time is reached Redis will log that a script is 930# still in execution after the maximum allowed time and will start to 931# reply to queries with an error. 932# 933# When a long running script exceeds the maximum execution time only the 934# SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be 935# used to stop a script that did not yet called write commands. The second 936# is the only way to shut down the server in the case a write command was 937# already issued by the script but the user doesn't want to wait for the natural 938# termination of the script. 939# 940# Set it to 0 or a negative value for unlimited execution without warnings. 941# 如果达到最大时间限制(毫秒),redis会记个log,然后返回error。 942当一个脚本超过了最大时限。只有SCRIPT KILLSHUTDOWN NOSAVE可以用。 943第一个可以杀没有调write命令的东西。要是已经调用了write,只能用第二个命令杀。 944lua-time-limit 5000 945################################ REDIS CLUSTER ############################### 946# 947# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 948# WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however 949# in order to mark it as "mature" we need to wait for a non trivial percentage 950# of users to deploy it in production. 951# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 952# 953# Normal Redis instances can't be part of a Redis Cluster; only nodes that are 954# started as cluster nodes can. In order to start a Redis instance as a 955# cluster node enable the cluster support uncommenting the following: 956# 957#集群开关,默认是不开启集群模式。 958# cluster-enabled yes 959# Every cluster node has a cluster configuration file. This file is not 960# intended to be edited by hand. It is created and updated by Redis nodes. 961# Every Redis Cluster node requires a different cluster configuration file. 962# Make sure that instances running in the same system do not have 963# overlapping cluster configuration file names. 964# 965#集群配置文件的名称,每个节点都有一个集群相关的配置文件, 966持久化保存集群的信息。这个文件并不需要手动配置,这个配置文件有Redis生成并更新, 967每个Redis集群节点需要一个单独的配置文件,请确保与实例运行的系统中配置文件名称不冲突 968# cluster-config-file nodes-6379.conf 969# Cluster node timeout is the amount of milliseconds a node must be unreachable 970# for it to be considered in failure state. 971# Most other internal time limits are multiple of the node timeout. 972# 973#节点互连超时的阀值。集群节点超时毫秒数 974# cluster-node-timeout 15000 975# A slave of a failing master will avoid to start a failover if its data 976# looks too old. 977# 978# There is no simple way for a slave to actually have an exact measure of 979# its "data age", so the following two checks are performed: 980# 981# 1) If there are multiple slaves able to failover, they exchange messages 982# in order to try to give an advantage to the slave with the best 983# replication offset (more data from the master processed). 984# Slaves will try to get their rank by offset, and apply to the start 985# of the failover a delay proportional to their rank. 986# 987# 2) Every single slave computes the time of the last interaction with 988# its master. This can be the last ping or command received (if the master 989# is still in the "connected" state), or the time that elapsed since the 990# disconnection with the master (if the replication link is currently down). 991# If the last interaction is too old, the slave will not try to failover 992# at all. 993# 994# The point "2" can be tuned by user. Specifically a slave will not perform 995# the failover if, since the last interaction with the master, the time 996# elapsed is greater than: 997# 998# (node-timeout * slave-validity-factor) + repl-ping-slave-period 999# 1000# So for example if node-timeout is 30 seconds, and the slave-validity-factor 1001# is 10, and assuming a default repl-ping-slave-period of 10 seconds, the 1002# slave will not try to failover if it was not able to talk with the master 1003# for longer than 310 seconds. 1004# 1005# A large slave-validity-factor may allow slaves with too old data to failover 1006# a master, while a too small value may prevent the cluster from being able to 1007# elect a slave at all. 1008# 1009# For maximum availability, it is possible to set the slave-validity-factor 1010# to a value of 0, which means, that slaves will always try to failover the 1011# master regardless of the last time they interacted with the master. 1012# (However they'll always try to apply a delay proportional to their 1013# offset rank). 1014# 1015# Zero is the only value able to guarantee that when all the partitions heal 1016# the cluster will always be able to continue. 1017# 1018 #在进行故障转移的时候,全部slave都会请求申请为master, 1019 但是有些slave可能与master断开连接一段时间了,导致数据过于陈旧, 1020 这样的slave不应该被提升为master。该参数就是用来判>断slave节点与master断线的时间是否过长。 1021 判断方法是: 1022 #比较slave断开连接的时间和(node-timeout * slave-validity-factor) + repl-ping-slave-period 1023 #如果节点超时时间为三十秒, 并且slave-validity-factor为10,假设默认的repl-ping-slave-period是10秒, 1024 即如果超过310秒slave将不会尝试进行故障转移 1025 #可能出现由于某主节点失联却没有从节点能顶上的情况,从而导致集群不能正常工作,在这种情况下, 1026 只有等到原来的主节点重新回归到集群,集群才恢复运作 1027 #如果设置成0,则无论从节点与主节点失联多久,从节点都会尝试升级成主节 1028 1029# cluster-slave-validity-factor 10 1030# Cluster slaves are able to migrate to orphaned masters, that are masters 1031# that are left without working slaves. This improves the cluster ability 1032# to resist to failures as otherwise an orphaned master can't be failed over 1033# in case of failure if it has no working slaves. 1034# 1035# Slaves migrate to orphaned masters only if there are still at least a 1036# given number of other working slaves for their old master. This number 1037# is the "migration barrier". A migration barrier of 1 means that a slave 1038# will migrate only if there is at least 1 other working slave for its master 1039# and so forth. It usually reflects the number of slaves you want for every 1040# master in your cluster. 1041# 1042# Default is 1 (slaves migrate only if their masters remain with at least 1043# one slave). To disable migration just set it to a very large value. 1044# A value of 0 can be set but is useful only for debugging and dangerous 1045# in production. 1046# 1047 #master的slave数量大于该值,slave才能迁移到其他孤立master上,如这个参数若被设为21048 那么只有当一个主节点拥有2 个可工作的从节点时,它的一个从节点会尝试迁移。 1049 #主节点需要的最小从节点数,只有达到这个数,主节点失败时,它从节点才会进行迁移。 1050 1051# cluster-migration-barrier 1 1052# By default Redis Cluster nodes stop accepting queries if they detect there 1053# is at least an hash slot uncovered (no available node is serving it). 1054# This way if the cluster is partially down (for example a range of hash slots 1055# are no longer covered) all the cluster becomes, eventually, unavailable. 1056# It automatically returns available as soon as all the slots are covered again. 1057# 1058# However sometimes you want the subset of the cluster which is working, 1059# to continue to accept queries for the part of the key space that is still 1060# covered. In order to do so, just set the cluster-require-full-coverage 1061# option to no. 1062# 1063 #默认情况下,集群全部的slot有节点分配,集群状态才为ok,才能提供服务。设置为no, 1064 可以在slot没有全部分配的时候提供服务。不建议打开该配置,这样会造成分区的时候, 1065 小分区的mster一直在接受写请求,而造成很长时间数据不一致。 1066 #在部分key所在的节点不可用时,如果此参数设置为”yes”(默认值), 1067 则整个集群停止接受操作;如果此参数设置为”no”,则集群依然为可达节点上的key提供读操作 1068 1069# cluster-require-full-coverage yes 1070# In order to setup your cluster make sure to read the documentation 1071# available at http://redis.io web site. 1072########################## CLUSTER DOCKER/NAT support ######################## 1073# In certain deployments, Redis Cluster nodes address discovery fails, because 1074# addresses are NAT-ted or because ports are forwarded (the typical case is 1075# Docker and other containers). 1076# 1077# In order to make Redis Cluster working in such environments, a static 1078# configuration where each node knows its public address is needed. The 1079# following two options are used for this scope, and are: 1080# 1081在某些部署中,Redis集群节点地址发现失败, 1082因为地址是NAT-ted或者因为端口被转发(典型的情况是# Docker和其他容器)1083#为了让Redis集群在这样的环境中工作,一个静态的每个节点知道其公开地址的配置。 1084的#此作用域使用了以下两个选项: 1085 ##实际为各节点网卡分配ip 先用上网关ip代替 1086# * cluster-announce-ip 1087 ##节点映射端口 1088# * cluster-announce-port 1089 ##节点总线端 1090# * cluster-announce-bus-port 1091# 1092# Each instruct the node about its address, client port, and cluster message 1093# bus port. The information is then published in the header of the bus packets 1094# so that other nodes will be able to correctly map the address of the node 1095# publishing the information. 1096# 1097# If the above options are not used, the normal Redis Cluster auto-detection 1098# will be used instead. 1099# 1100# Note that when remapped, the bus port may not be at the fixed offset of 1101# clients port + 10000, so you can specify any port and bus-port depending 1102# on how they get remapped. If the bus-port is not set, a fixed offset of 1103# 10000 will be used as usually. 1104# 1105# Example: 1106# 1107每个节点指示其地址、客户端端口和集群消息#总线端口。然后,这些信息被发布在总线数据包 1108的报头中使其他节点能够正确映射节点的地址#发布的信息。#如果不使用上述选项, 1109正常的Redis集群自动检测将被使用。#注意,当重新映射时,总线端口可能不在固定偏移量 1110上# clients port + 10000,因此您可以指定任意端口和总线端口他们是如何被重拍的。 1111如果总线端口没有设置,则为一个固定的偏移量# 10000将像往常一样使用。##的例子: 1112# cluster-announce-ip 10.1.1.5 1113# cluster-announce-port 6379 1114# cluster-announce-bus-port 6380 1115################################## SLOW LOG ################################### 1116# The Redis Slow Log is a system to log queries that exceeded a specified 1117# execution time. The execution time does not include the I/O operations 1118# like talking with the client, sending the reply and so forth, 1119# but just the time needed to actually execute the command (this is the only 1120# stage of command execution where the thread is blocked and can not serve 1121# other requests in the meantime). 1122# 1123# You can configure the slow log with two parameters: one tells Redis 1124# what is the execution time, in microseconds, to exceed in order for the 1125# command to get logged, and the other parameter is the length of the 1126# slow log. When a new command is logged the oldest one is removed from the 1127# queue of logged commands. 1128# The following time is expressed in microseconds, so 1000000 is equivalent 1129# to one second. Note that a negative number disables the slow log, while 1130# a value of zero forces the logging of every command. 1131###slog log是用来记录redis运行中执行比较慢的命令耗时。当命令的执行超过了指定时间, 1132就记录在slow log中,slog log保存在内存中,所以没有IO操作。 1133#执行时间比slowlog-log-slower-than大的请求记录到slowlog里面,单位是微秒, 1134所以1000000就是1秒。注意,负数时间会禁用慢查询日志,而0则会强制记录所有命令。 1135slowlog-log-slower-than 10000 1136# There is no limit to this length. Just be aware that it will consume memory. 1137# You can reclaim memory used by the slow log with SLOWLOG RESET. 1138#慢查询日志长度。当一个新的命令被写进日志的时候,最老的那个记录会被删掉。 1139这个长度没有限制。只要有足够的内存就行。你可以通过 SLOWLOG RESET 来释放内存。 1140slowlog-max-len 128 1141################################ LATENCY MONITOR ############################## 1142# The Redis latency monitoring subsystem samples different operations 1143# at runtime in order to collect data related to possible sources of 1144# latency of a Redis instance. 1145# 1146# Via the LATENCY command this information is available to the user that can 1147# print graphs and obtain reports. 1148# 1149# The system only logs operations that were performed in a time equal or 1150# greater than the amount of milliseconds specified via the 1151# latency-monitor-threshold configuration directive. When its value is set 1152# to zero, the latency monitor is turned off. 1153# 1154# By default latency monitoring is disabled since it is mostly not needed 1155# if you don't have latency issues, and collecting data has a performance 1156# impact, that while very small, can be measured under big load. Latency 1157# monitoring can easily be enabled at runtime using the command 1158# "CONFIG SET latency-monitor-threshold <milliseconds>" if needed. 1159#延迟监控功能是用来监控redis中执行比较缓慢的一些操作,用LATENCY打印redis实例在跑命令时的耗时图表。 1160只记录大于等于下边设置的值的操作。0的话,就是关闭监视。默认延迟监控功能是关闭的, 1161如果你需要打开,也可以通过CONFIG SET命令动态设置。 1162latency-monitor-threshold 0 1163############################# EVENT NOTIFICATION ############################## 1164# Redis can notify Pub/Sub clients about events happening in the key space. 1165# This feature is documented at http://redis.io/topics/notifications 1166# 1167# For instance if keyspace events notification is enabled, and a client 1168# performs a DEL operation on key "foo" stored in the Database 0, two 1169# messages will be published via Pub/Sub: 1170# 1171# PUBLISH __keyspace@0__:foo del 1172# PUBLISH __keyevent@0__:del foo 1173# 1174# It is possible to select the events that Redis will notify among a set 1175# of classes. Every class is identified by a single character: 1176# 1177# K Keyspace events, published with __keyspace@<db>__ prefix. 1178# E Keyevent events, published with __keyevent@<db>__ prefix. 1179# g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ... 1180# $ String commands 1181# l List commands 1182# s Set commands 1183# h Hash commands 1184# z Sorted set commands 1185# x Expired events (events generated every time a key expires) 1186# e Evicted events (events generated when a key is evicted for maxmemory) 1187# A Alias for g$lshzxe, so that the "AKE" string means all the events. 1188# 1189# The "notify-keyspace-events" takes as argument a string that is composed 1190# of zero or multiple characters. The empty string means that notifications 1191# are disabled. 1192# 1193# Example: to enable list and generic events, from the point of view of the 1194# event name, use: 1195# 1196# notify-keyspace-events Elg 1197# 1198# Example 2: to get the stream of the expired keys subscribing to channel 1199# name __keyevent@0__:expired use: 1200# 1201# notify-keyspace-events Ex 1202# 1203# By default all notifications are disabled because most users don't need 1204# this feature and the feature has some overhead. Note that if you don't 1205# specify at least one of K or E, no events will be delivered. 1206#键空间通知使得客户端可以通过订阅频道或模式,来接收那些以某种方式改动了 Redis 数据集的事件。 1207因为开启键空间通知功能需要消耗一些 CPU ,所以在默认配置下,该功能处于关闭状态。 1208#notify-keyspace-events 的参数可以是以下字符的任意组合,它指定了服务器该发送哪些类型的通知: 1209##K 键空间通知,所有通知以 __keyspace@__ 为前缀 1210##E 键事件通知,所有通知以 __keyevent@__ 为前缀 1211##g DELEXPIRERENAME 等类型无关的通用命令的通知 1212##$ 字符串命令的通知 1213##l 列表命令的通知 1214##s 集合命令的通知 1215##h 哈希命令的通知 1216##z 有序集合命令的通知 1217##x 过期事件:每当有过期键被删除时发送 1218##e 驱逐(evict)事件:每当有键因为 maxmemory 政策而被删除时发送 1219##A 参数 g$lshzxe 的别名 1220#输入的参数中至少要有一个 K 或者 E,否则的话,不管其余的参数是什么,都不会有任何 通知被分发。 1221详细使用可以参考http://redis.io/topics/notifications 1222 1223notify-keyspace-events "" 1224############################### ADVANCED CONFIG ############################### 1225# Hashes are encoded using a memory efficient data structure when they have a 1226# small number of entries, and the biggest entry does not exceed a given 1227# threshold. These thresholds can be configured using the following directives. 1228#数据量小于等于hash-max-ziplist-entries的用ziplist,大于hash-max-ziplist-entries用hash 1229hash-max-ziplist-entries 512 1230#value大小小于等于hash-max-ziplist-value的用ziplist,大于hash-max-ziplist-value用hash。 1231hash-max-ziplist-value 64 1232# Lists are also encoded in a special way to save a lot of space. 1233# The number of entries allowed per internal list node can be specified 1234# as a fixed maximum size or a maximum number of elements. 1235# For a fixed maximum size, use -5 through -1, meaning: 1236# -5: max size: 64 Kb <-- not recommended for normal workloads 1237# -4: max size: 32 Kb <-- not recommended 1238# -3: max size: 16 Kb <-- probably not recommended 1239# -2: max size: 8 Kb <-- good 1240# -1: max size: 4 Kb <-- good 1241# Positive numbers mean store up to _exactly_ that number of elements 1242# per list node. 1243# The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size), 1244# but if your use case is unique, adjust the settings as necessary. 1245list-max-ziplist-size -2 1246# Lists may also be compressed. 1247# Compress depth is the number of quicklist ziplist nodes from *each* side of 1248# the list to *exclude* from compression. The head and tail of the list 1249# are always uncompressed for fast push/pop operations. Settings are: 1250# 0: disable all list compression 1251# 1: depth 1 means "don't start compressing until after 1 node into the list, 1252# going from either the head or tail" 1253# So: [head]->node->node->...->node->[tail] 1254# [head], [tail] will always be uncompressed; inner nodes will compress. 1255# 2: [head]->[next]->node->node->...->node->[prev]->[tail] 1256# 2 here means: don't compress head or head->next or tail->prev or tail, 1257# but compress all nodes between them. 1258# 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail] 1259# etc. 1260list-compress-depth 0 1261# Sets have a special encoding in just one case: when a set is composed 1262# of just strings that happen to be integers in radix 10 in the range 1263# of 64 bit signed integers. 1264# The following configuration setting sets the limit in the size of the 1265# set in order to use this special memory saving encoding. 1266set-max-intset-entries 512 1267# Similarly to hashes and lists, sorted sets are also specially encoded in 1268# order to save a lot of space. This encoding is only used when the length and 1269# elements of a sorted set are below the following limits: 1270zset-max-ziplist-entries 128 1271zset-max-ziplist-value 64 1272# HyperLogLog sparse representation bytes limit. The limit includes the 1273# 16 bytes header. When an HyperLogLog using the sparse representation crosses 1274# this limit, it is converted into the dense representation. 1275# 1276# A value greater than 16000 is totally useless, since at that point the 1277# dense representation is more memory efficient. 1278# 1279# The suggested value is ~ 3000 in order to have the benefits of 1280# the space efficient encoding without slowing down too much PFADD, 1281# which is O(N) with the sparse encoding. The value can be raised to 1282# ~ 10000 when CPU is not a concern, but space is, and the data set is 1283# composed of many HyperLogLogs with cardinality in the 0 - 15000 range. 1284hll-sparse-max-bytes 3000 1285# Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in 1286# order to help rehashing the main Redis hash table (the one mapping top-level 1287# keys to values). The hash table implementation Redis uses (see dict.c) 1288# performs a lazy rehashing: the more operation you run into a hash table 1289# that is rehashing, the more rehashing "steps" are performed, so if the 1290# server is idle the rehashing is never complete and some more memory is used 1291# by the hash table. 1292# 1293# The default is to use this millisecond 10 times every second in order to 1294# actively rehash the main dictionaries, freeing memory when possible. 1295# 1296# If unsure: 1297# use "activerehashing no" if you have hard latency requirements and it is 1298# not a good thing in your environment that Redis can reply from time to time 1299# to queries with 2 milliseconds delay. 1300# 1301# use "activerehashing yes" if you don't have such hard requirements but 1302# want to free memory asap when possible. 1303activerehashing yes 1304# The client output buffer limits can be used to force disconnection of clients 1305# that are not reading data from the server fast enough for some reason (a 1306# common reason is that a Pub/Sub client can't consume messages as fast as the 1307# publisher can produce them). 1308# 1309# The limit can be set differently for the three different classes of clients: 1310# 1311# normal -> normal clients including MONITOR clients 1312# slave -> slave clients 1313# pubsub -> clients subscribed to at least one pubsub channel or pattern 1314# 1315# The syntax of every client-output-buffer-limit directive is the following: 1316# 1317# client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds> 1318# 1319# A client is immediately disconnected once the hard limit is reached, or if 1320# the soft limit is reached and remains reached for the specified number of 1321# seconds (continuously). 1322# So for instance if the hard limit is 32 megabytes and the soft limit is 1323# 16 megabytes / 10 seconds, the client will get disconnected immediately 1324# if the size of the output buffers reach 32 megabytes, but will also get 1325# disconnected if the client reaches 16 megabytes and continuously overcomes 1326# the limit for 10 seconds. 1327# 1328# By default normal clients are not limited because they don't receive data 1329# without asking (in a push way), but just after a request, so only 1330# asynchronous clients may create a scenario where data is requested faster 1331# than it can read. 1332# 1333# Instead there is a default limit for pubsub and slave clients, since 1334# subscribers and slaves receive data in a push fashion. 1335# 1336# Both the hard or the soft limit can be disabled by setting them to zero. 1337client-output-buffer-limit normal 0 0 0 1338client-output-buffer-limit slave 256mb 64mb 60 1339client-output-buffer-limit pubsub 32mb 8mb 60 1340# Client query buffers accumulate new commands. They are limited to a fixed 1341# amount by default in order to avoid that a protocol desynchronization (for 1342# instance due to a bug in the client) will lead to unbound memory usage in 1343# the query buffer. However you can configure it here if you have very special 1344# needs, such us huge multi/exec requests or alike. 1345# 1346# client-query-buffer-limit 1gb 1347# In the Redis protocol, bulk requests, that are, elements representing single 1348# strings, are normally limited ot 512 mb. However you can change this limit 1349# here. 1350# 1351# proto-max-bulk-len 512mb 1352# Redis calls an internal function to perform many background tasks, like 1353# closing connections of clients in timeout, purging expired keys that are 1354# never requested, and so forth. 1355# 1356# Not all tasks are performed with the same frequency, but Redis checks for 1357# tasks to perform according to the specified "hz" value. 1358# 1359# By default "hz" is set to 10. Raising the value will use more CPU when 1360# Redis is idle, but at the same time will make Redis more responsive when 1361# there are many keys expiring at the same time, and timeouts may be 1362# handled with more precision. 1363# 1364# The range is between 1 and 500, however a value over 100 is usually not 1365# a good idea. Most users should use the default of 10 and raise this up to 1366# 100 only in environments where very low latency is required. 1367hz 10 1368# When a child rewrites the AOF file, if the following option is enabled 1369# the file will be fsync-ed every 32 MB of data generated. This is useful 1370# in order to commit the file to the disk more incrementally and avoid 1371# big latency spikes. 1372aof-rewrite-incremental-fsync yes 1373# Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good 1374# idea to start with the default settings and only change them after investigating 1375# how to improve the performances and how the keys LFU change over time, which 1376# is possible to inspect via the OBJECT FREQ command. 1377# 1378# There are two tunable parameters in the Redis LFU implementation: the 1379# counter logarithm factor and the counter decay time. It is important to 1380# understand what the two parameters mean before changing them. 1381# 1382# The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis 1383# uses a probabilistic increment with logarithmic behavior. Given the value 1384# of the old counter, when a key is accessed, the counter is incremented in 1385# this way: 1386# 1387# 1. A random number R between 0 and 1 is extracted. 1388# 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1). 1389# 3. The counter is incremented only if R < P. 1390# 1391# The default lfu-log-factor is 10. This is a table of how the frequency 1392# counter changes with a different number of accesses with different 1393# logarithmic factors: 1394# 1395# +--------+------------+------------+------------+------------+------------+ 1396# | factor | 100 hits | 1000 hits | 100K hits | 1M hits | 10M hits | 1397# +--------+------------+------------+------------+------------+------------+ 1398# | 0 | 104 | 255 | 255 | 255 | 255 | 1399# +--------+------------+------------+------------+------------+------------+ 1400# | 1 | 18 | 49 | 255 | 255 | 255 | 1401# +--------+------------+------------+------------+------------+------------+ 1402# | 10 | 10 | 18 | 142 | 255 | 255 | 1403# +--------+------------+------------+------------+------------+------------+ 1404# | 100 | 8 | 11 | 49 | 143 | 255 | 1405# +--------+------------+------------+------------+------------+------------+ 1406# 1407# NOTE: The above table was obtained by running the following commands: 1408# 1409# redis-benchmark -n 1000000 incr foo 1410# redis-cli object freq foo 1411# 1412# NOTE 2: The counter initial value is 5 in order to give new objects a chance 1413# to accumulate hits. 1414# 1415# The counter decay time is the time, in minutes, that must elapse in order 1416# for the key counter to be divided by two (or decremented if it has a value 1417# less <= 10). 1418# 1419# The default value for the lfu-decay-time is 1. A Special value of 0 means to 1420# decay the counter every time it happens to be scanned. 1421# 1422# lfu-log-factor 10 1423# lfu-decay-time 1 1424########################### ACTIVE DEFRAGMENTATION ####################### 1425# 1426# WARNING THIS FEATURE IS EXPERIMENTAL. However it was stress tested 1427# even in production and manually tested by multiple engineers for some 1428# time. 1429# 1430# What is active defragmentation? 1431# ------------------------------- 1432# 1433# Active (online) defragmentation allows a Redis server to compact the 1434# spaces left between small allocations and deallocations of data in memory, 1435# thus allowing to reclaim back memory. 1436# 1437# Fragmentation is a natural process that happens with every allocator (but 1438# less so with Jemalloc, fortunately) and certain workloads. Normally a server 1439# restart is needed in order to lower the fragmentation, or at least to flush 1440# away all the data and create it again. However thanks to this feature 1441# implemented by Oran Agra for Redis 4.0 this process can happen at runtime 1442# in an "hot" way, while the server is running. 1443# 1444# Basically when the fragmentation is over a certain level (see the 1445# configuration options below) Redis will start to create new copies of the 1446# values in contiguous memory regions by exploiting certain specific Jemalloc 1447# features (in order to understand if an allocation is causing fragmentation 1448# and to allocate it in a better place), and at the same time, will release the 1449# old copies of the data. This process, repeated incrementally for all the keys 1450# will cause the fragmentation to drop back to normal values. 1451# 1452# Important things to understand: 1453# 1454# 1. This feature is disabled by default, and only works if you compiled Redis 1455# to use the copy of Jemalloc we ship with the source code of Redis. 1456# This is the default with Linux builds. 1457# 1458# 2. You never need to enable this feature if you don't have fragmentation 1459# issues. 1460# 1461# 3. Once you experience fragmentation, you can enable this feature when 1462# needed with the command "CONFIG SET activedefrag yes". 1463# 1464# The configuration parameters are able to fine tune the behavior of the 1465# defragmentation process. If you are not sure about what they mean it is 1466# a good idea to leave the defaults untouched. 1467# Enabled active defragmentation 1468# activedefrag yes 1469# Minimum amount of fragmentation waste to start active defrag 1470# active-defrag-ignore-bytes 100mb 1471# Minimum percentage of fragmentation to start active defrag 1472# active-defrag-threshold-lower 10 1473# Maximum percentage of fragmentation at which we use maximum effort 1474# active-defrag-threshold-upper 100 1475# Minimal effort for defrag in CPU percentage 1476# active-defrag-cycle-min 25 1477# Maximal effort for defrag in CPU percentage 1478# active-defrag-cycle-max 75
点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )