①、slave-serve-stale-data:默认值为yes。当一个 slave 与 master 失去联系,或者复制正在进行的时候,slave 可能会有两种表现:
1) 如果为 yes ,slave 仍然会应答客户端请求,但返回的数据可能是过时,或者数据可能是空的在第一次同步的时候
2) 如果为 no ,在你执行除了 info he salveof 之外的其他命令时,slave 都将返回一个 "SYNC with master in progress" 的错误
②、slave-read-only:配置Redis的Slave实例是否接受写操作,即Slave是否为只读Redis。默认值为yes。
③、repl-diskless-sync:主从数据复制是否使用无硬盘复制功能。默认值为no。
④、repl-diskless-sync-delay:当启用无硬盘备份,服务器等待一段时间后才会通过套接字向从站传送RDB文件,这个等待时间是可配置的。这一点很重要,因为一旦传送开始,就不可能再为一个新到达的从站服务。从站则要排队等待下一次RDB传送。因此服务器等待一段 时间以期更多的从站到达。延迟时间以秒为单位,默认为5秒。要关掉这一功能,只需将它设置为0秒,传送会立即启动。默认值为5。
⑤、repl-disable-tcp-nodelay:同步之后是否禁用从站上的TCP_NODELAY 如果你选择yes,redis会使用较少量的TCP包和带宽向从站发送数据。但这会导致在从站增加一点数据的延时。Linux内核默认配置情况下最多40毫秒的延时。如果选择no,从站的数据延时不会那么多,但备份需要的带宽相对较多。默认情况下我们将潜在因素优化,但在高负载情况下或者在主从站都跳的情况下,把它切换为yes是个好主意。默认值为no。
KEYS TRACKING
1KEYS TRACKING 2# Redis为客户端的值缓存实现服务器辅助的支持。这是使用无效表实现的,该无效表使用1600万个插槽记住哪些客户端可能具有某些键子集。依次将其用于向客户端发送无效消息 3Redis implements server assisted support for client side caching of values. 4This is implemented using an invalidation table that remembers, using 516 millions of slots, what clients may have certain subsets of keys. In turn 6this is used in order to send invalidation messages to clients. Please 7check this page to understand more about the feature: 8 9https://redis.io/topics/client-side-caching 10 11When tracking is enabled for a client, all the read only queries are assumed 12to be cached: this will force Redis to store information in the invalidation 13table. When keys are modified, such information is flushed away, and 14invalidation messages are sent to the clients. However if the workload is 15heavily dominated by reads, Redis could use more and more memory in order 16to track the keys fetched by many clients. 17# 为客户端启用跟踪时,假定所有只读查询都已缓存:这将强制Redis将信息存储在失效表中。修改密钥后,将清除此类信息,并将无效消息发送给客户端。但是,如果工作负载主要由读取控制,则Redis可能会使用越来越多的内存来跟踪许多客户端获取的密钥 18For this reason it is possible to configure a maximum fill value for the 19invalidation table. By default it is set to 1M of keys, and once this limit 20is reached, Redis will start to evict keys in the invalidation table 21even if they were not modified, just to reclaim memory: this will in turn 22force the clients to invalidate the cached values. Basically the table 23maximum size is a trade off between the memory you want to spend server 24side to track information about who cached what, and the ability of clients 25to retain cached objects in memory. 26 27# 如果将值设置为0,则表示没有限制,Redis将在失效表中保留所需数量的键。在“统计信息”信息部分中,您可以找到有关每个给定时刻失效表中的键数的信息。 28If you set the value to 0, it means there are no limits, and Redis will 29retain as many keys as needed in the invalidation table. 30In the "stats" INFO section, you can find information about the number of 31keys in the invalidation table at every given moment. 32 33Note: when key tracking is used in broadcasting mode, no memory is used 34in the server side so this setting is useless. 35 36tracking-table-max-keys 1000000
SECURITY(重要)
1SECURITY 2 3Warning: since Redis is pretty fast, an outside user can try up to 41 million passwords per second against a modern box. This means that you 5should use very strong passwords, otherwise they will be very easy to break. 6Note that because the password is really a shared secret between the client 7and the server, and should not be memorized by any human, the password 8can be easily a long string from /dev/urandom or whatever, so by using a 9long and unguessable password no brute force attack will be possible. 10# 警告:由于Redis的速度非常快,因此外部用户每秒可以在一个现代机器上尝试最多100万个密码。这意味着您应该使用非常安全的密码,否则密码很容易破解。 11# 请注意,由于该密码实际上是客户端和服务器之间的共享机密,并且不应被任何人记住,因此该密码可以很容易地是来自devurandom或其他任何形式的长字符串,因此使用长而毫无疑问的密码不会造成暴力攻击是可能的 12Redis ACL users are defined in the following format: 13 14user <username> ... acl rules ... 15 16For example: 17 18user worker +@list +@connection ~jobs:* on >ffa9203c493aa99 19 20The special username "default" is used for new connections. If this user 21has the "nopass" rule, then new connections will be immediately authenticated 22as the "default" user without the need of any password provided via the 23AUTH command. Otherwise if the "default" user is not flagged with "nopass" 24the connections will start in not authenticated state, and will require 25AUTH (or the HELLO command AUTH option) in order to be authenticated and 26start to work. 27# 特殊的用户名“默认”用于新连接。如果该用户具有“ nopass”规则,则新连接将立即被认证为“默认”用户,而不需要通过AUTH命令提供的任何密码。否则,如果未将“默认”用户标记为“ nopass”,则连接将以未认证状态启动,并且需要AUTH(或HELLO命令AUTH选项)才能进行认证并开始工作 28The ACL rules that describe what a user can do are the following: 29 30on Enable the user: it is possible to authenticate as this user. 31off Disable the user: it's no longer possible to authenticate 32 with this user, however the already authenticated connections 33 will still work. 34+<command> Allow the execution of that command 35-<command> Disallow the execution of that command 36+@<category> Allow the execution of all the commands in such category 37 with valid categories are like @admin, @set, @sortedset, ... 38 and so forth, see the full list in the server.c file where 39 the Redis command table is described and defined. 40 The special category @all means all the commands, but currently 41 present in the server, and that will be loaded in the future 42 via modules. 43+<command>|subcommand Allow a specific subcommand of an otherwise 44 disabled command. Note that this form is not 45 allowed as negative like -DEBUG|SEGFAULT, but 46 only additive starting with "+". 47allcommands Alias for +@all. Note that it implies the ability to execute 48 all the future commands loaded via the modules system. 49nocommands Alias for -@all. 50~<pattern> Add a pattern of keys that can be mentioned as part of 51 commands. For instance ~* allows all the keys. The pattern 52 is a glob-style pattern like the one of KEYS. 53 It is possible to specify multiple patterns. 54allkeys Alias for ~* 55resetkeys Flush the list of allowed keys patterns. 56><password> Add this password to the list of valid password for the user. 57 For example >mypass will add "mypass" to the list. 58 This directive clears the "nopass" flag (see later). 59<<password> Remove this password from the list of valid passwords. 60nopass All the set passwords of the user are removed, and the user 61 is flagged as requiring no password: it means that every 62 password will work against this user. If this directive is 63 used for the default user, every new connection will be 64 immediately authenticated with the default user without 65 any explicit AUTH command required. Note that the "resetpass" 66 directive will clear this condition. 67resetpass Flush the list of allowed passwords. Moreover removes the 68 "nopass" status. After "resetpass" the user has no associated 69 passwords and there is no way to authenticate without adding 70 some password (or setting it as "nopass" later). 71reset Performs the following actions: resetpass, resetkeys, off, 72 -@all. The user returns to the same state it has immediately 73 after its creation. 74 75ACL rules can be specified in any order: for instance you can start with 76passwords, then flags, or key patterns. However note that the additive 77and subtractive rules will CHANGE MEANING depending on the ordering. 78For instance see the following example: 79 80user alice on +@all -DEBUG ~* >somepassword 81 82This will allow "alice" to use all the commands with the exception of the 83DEBUG command, since +@all added all the commands to the set of the commands 84alice can use, and later DEBUG was removed. However if we invert the order 85of two ACL rules the result will be different: 86# 这将允许“ alice”使用除DEBUG命令之外的所有命令,因为+ @ all将所有命令添加到了alice可以使用的命令集中,并且后来删除了DEBUG。但是,如果我们颠倒两个ACL规则的顺序,结果将有所不同 87user alice on -DEBUG +@all ~* >somepassword 88 89Now DEBUG was removed when alice had yet no commands in the set of allowed 90commands, later all the commands are added, so the user will be able to 91execute everything. 92 93Basically ACL rules are processed left-to-right. 94 95For more information about ACL configuration please refer to 96the Redis web site at https://redis.io/topics/acl 97 98ACL LOG 99 100The ACL Log tracks failed commands and authentication events associated 101with ACLs. The ACL Log is useful to troubleshoot failed commands blocked 102by ACLs. The ACL Log is stored in memory. You can reclaim memory with 103ACL LOG RESET. Define the maximum entry length of the ACL Log below. 104acllog-max-len 128 105# ACL日志跟踪与ACL关联的失败命令和身份验证事件。ACL日志可用于对ACL阻止的失败命令进行故障排除。ACL日志存储在内存中。您可以使用ACL LOG RESET回收内存。在下面定义ACL日志的最大输入长度。acllog-max-len 128 106Using an external ACL file 107 108Instead of configuring users here in this file, it is possible to use 109a stand-alone file just listing users. The two methods cannot be mixed: 110if you configure users here and at the same time you activate the external 111ACL file, the server will refuse to start. 112# 除了在此文件中配置用户之外,还可以使用仅列出用户的独立文件。两种方法不能混用:如果您在此处配置用户并同时激活外部ACL文件,则服务器将拒绝启动 113The format of the external ACL user file is exactly the same as the 114format that is used inside redis.conf to describe users. 115 116aclfile /etc/redis/users.acl 117 118IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility 119layer on top of the new ACL system. The option effect will be just setting 120the password for the default user. Clients will still authenticate using 121AUTH <password> as usually, or more explicitly with AUTH default <password> 122if they follow the new protocol: both will work. 123# 重要说明:从Redis 6开始,“ requirepass”只是新ACL系统之上的兼容性层。选项效果将只是为默认用户设置密码。客户端仍将照常使用AUTH <password>进行身份验证,如果遵循新协议,则仍将使用AUTH default <password>进行更明确的身份验证 124requirepass foobared 125 126Command renaming (DEPRECATED). 127 128------------------------------------------------------------------------ 129WARNING: avoid using this option if possible. Instead use ACLs to remove 130commands from the default user, and put them only in some admin user you 131create for administrative purposes. 132------------------------------------------------------------------------ 133# 警告:尽可能避免使用此选项。而是使用ACL从默认用户中删除命令,并将其仅放置在您出于管理目的而创建的某些admin用户中 134It is possible to change the name of dangerous commands in a shared 135environment. For instance the CONFIG command may be renamed into something 136hard to guess so that it will still be available for internal-use tools 137but not available for general clients. 138# 可以在共享环境中更改危险命令的名称。例如,CONFIG命令可能会重命名为一些难以猜测的名称,因此它仍可用于内部使用的工具,但不适用于一般客户 139Example: 140 141rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52 142 143It is also possible to completely kill a command by renaming it into 144an empty string: 145 146rename-command CONFIG "" 147 148Please note that changing the name of commands that are logged into the 149AOF file or transmitted to replicas may cause problems. 150# 注意,更改登录到AOF文件或传输到副本的命令的名称可能会导致问题
rename-command:命令重命名,对于一些危险命令例如:
- flushdb(清空数据库)
- flushall(清空所有记录)
- config(客户端连接后可配置服务器)
- keys(客户端连接后可查看所有存在的键)
作为服务端redis-server,常常需要禁用以上命令来使得服务器更加安全,禁用的具体做法是是:
rename-command FLUSHALL ""
也可以保留命令但是不能轻易使用,重命名这个命令即可:
- rename-command FLUSHALL abcdefg 这样,重启服务器后则需要使用新命令来执行操作,否则服务器会报错unknown command。
requirepass:设置redis连接密码
比如: requirepass 123456 表示redis的连接密码为123456.
CLIENTS
1CLIENTS 2 3Set the max number of connected clients at the same time. By default 4this limit is set to 10000 clients, however if the Redis server is not 5able to configure the process file limit to allow for the specified limit 6the max number of allowed clients is set to the current file limit 7minus 32 (as Redis reserves a few file descriptors for internal uses). 8# 同时设置最大连接客户端数。默认情况下,此限制设置为10000个客户端,但是,如果Redis服务器无法将进程文件限制配置为允许指定的限制,则允许的最大客户端数设置为当前文件限制减去32(因为Redis保留了内部使用的几个文件描述符) 9Once the limit is reached Redis will close all the new connections sending 10an error 'max number of clients reached'. 11# 达到限制后,Redis将关闭所有新连接,并发送错误消息“已达到最大客户端数”。 12IMPORTANT: When Redis Cluster is used, the max number of connections is also 13shared with the cluster bus: every node in the cluster will use two 14connections, one incoming and another outgoing. It is important to size the 15limit accordingly in case of very large clusters. 16# 重要信息:使用Redis群集时,最大连接数也与群集总线共享:群集中的每个节点将使用两个连接,一个进入,另一个向外。在群集非常大的情况下,相应地调整限制大小非常重要 17maxclients 10000
maxclients :设置客户端最大并发连接数,默认无限制,Redis可以同时打开的客户端连接数为Redis进程可以打开的最大文件。描述符数-32(redis server自身会使用一些),如果设置 maxclients为0 。表示不作限制。当客户端连接数到达限制时,Redis会关闭新的连接并向客户端返回max number of clients reached错误信息
MEMORY MANAGEMENT
1MEMORY MANAGEMENT 2 3Set a memory usage limit to the specified amount of bytes. 4When the memory limit is reached Redis will try to remove keys 5according to the eviction policy selected (see maxmemory-policy). 6# 将内存使用限制设置为指定的字节数。当达到内存限制时,Redis将尝试根据所选的逐出策略来删除密钥 7If Redis can't remove keys according to the policy, or if the policy is 8set to 'noeviction', Redis will start to reply with errors to commands 9that would use more memory, like SET, LPUSH, and so on, and will continue 10to reply to read-only commands like GET. 11# 如果Redis无法根据该策略删除密钥,或者如果该策略设置为'noeviction',则Redis将开始对将使用更多内存的命令(例如SET,LPUSH等)进行错误答复,并将继续回复诸如GET之类的只读命令 12This option is usually useful when using Redis as an LRU or LFU cache, or to 13set a hard memory limit for an instance (using the 'noeviction' policy). 14# 当将Redis用作LRU或LFU缓存,或为实例设置硬盘限制时,此选项通常很有用 15WARNING: If you have replicas attached to an instance with maxmemory on, 16the size of the output buffers needed to feed the replicas are subtracted 17from the used memory count, so that network problems / resyncs will 18not trigger a loop where keys are evicted, and in turn the output 19buffer of replicas is full with DELs of keys evicted triggering the deletion 20of more keys, and so forth until the database is completely emptied. 21# 警告:如果您将副本附加到实例上且maxmemory处于打开状态,则从使用的内存计数中减去提供副本所需的输出缓冲区的大小,以便网络问题重新同步将不会触发逐出密钥的循环。使副本的输出缓冲区已满,其中有被驱逐的键DEL触发了更多键的删除,依此类推,直到数据库完全清空 22In short... if you have replicas attached it is suggested that you set a lower 23limit for maxmemory so that there is some free RAM on the system for replica 24output buffers (but this is not needed if the policy is 'noeviction'). 25# 简而言之...如果您附加了副本,建议您为maxmemory设置一个下限,以便系统上有一些可用的RAM用于副本输出缓冲区(但是如果策略为“ noeviction”,则不需要这样做) 26maxmemory <bytes> 27 28MAXMEMORY POLICY: how Redis will select what to remove when maxmemory 29is reached. You can select one from the following behaviors: 30# MAXMEMORY POLICY:达到maxmemory后,Redis将如何选择要删除的内容。您可以从以下行为中选择一种 31volatile-lru -> Evict using approximated LRU, only keys with an expire set. 32allkeys-lru -> Evict any key using approximated LRU. 33volatile-lfu -> Evict using approximated LFU, only keys with an expire set. # 使用近似的LRU驱逐,仅使用已过期的密钥 34allkeys-lfu -> Evict any key using approximated LFU. # 使用近似的LFU退出任何密钥 35volatile-random -> Remove a random key having an expire set. # 删除具有过期设置的随机密钥 36allkeys-random -> Remove a random key, any key. # 删除随机密钥,任何密钥 37volatile-ttl -> Remove the key with the nearest expire time (minor TTL) # 取出最接近到期时间(较小的TTL)的密钥 38noeviction -> Don't evict anything, just return an error on write operations. # 不驱逐任何东西,仅在写操作时返回错误 39 40LRU means Least Recently Used # LRU表示最近最少使用 LFU表示最少使用 41LFU means Least Frequently Used 42 43Both LRU, LFU and volatile-ttl are implemented using approximated 44randomized algorithms. 45# LRU,LFU和volatile-ttl均使用近似随机算法实现 46 47Note: with any of the above policies, Redis will return an error on write 48 operations, when there are no suitable keys for eviction. 49 50 At the date of writing these commands are: set setnx setex append 51 incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd 52 sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby 53 zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby 54 getset mset msetnx exec sort 55# 注意:使用上述任何策略时,如果没有合适的退出键,Redis将在写入操作中返回错误。在撰写本文时,这些命令是: 56# set setnx setex append incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd interinterstore sunion 57# sunionstore sdiff sdiffstore zadd zincrby zunionstore zinterstore hset hsetnx hmset hincrby mcrby deby byby 58The default is: 59 60maxmemory-policy noeviction 61 62LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated 63algorithms (in order to save memory), so you can tune it for speed or 64accuracy. By default Redis will check five keys and pick the one that was 65used least recently, you can change the sample size using the following 66configuration directive. 67# LRU,LFU和最小TTL算法不是精确算法,而是近似算法(以节省内存),因此您可以针对速度或准确性进行调整。默认情况下,Redis将检查五个键并选择最近使用最少的键,您可以使用以下配置指令更改样本大小 68The default of 5 produces good enough results. 10 Approximates very closely 69true LRU but costs more CPU. 3 is faster but not very accurate. 70# 默认值为5会产生足够好的结果。10非常接近真实的LRU,但是会花费更多的CPU。3更快但不是很准确 71maxmemory-samples 5 72 73Starting from Redis 5, by default a replica will ignore its maxmemory setting 74(unless it is promoted to master after a failover or manually). It means 75that the eviction of keys will be just handled by the master, sending the 76DEL commands to the replica as keys evict in the master side. 77# 从Redis 5开始,默认情况下,副本将忽略其maxmemory设置(除非在故障转移后或手动提升为主副本)。这意味着密钥的移出将仅由主服务器处理,将DEL命令作为副本在主计算机侧逐出,将DEL命令发送到副本 78This behavior ensures that masters and replicas stay consistent, and is usually 79what you want, however if your replica is writable, or you want the replica 80to have a different memory setting, and you are sure all the writes performed 81to the replica are idempotent, then you may change this default (but be sure 82to understand what you are doing). 83# 此行为可确保主副本和副本始终保持一致,这通常是您想要的,但是,如果副本是可写的,或者您希望副本具有不同的内存设置,并且您确定对副本执行的所有写操作都是幂等的,那么您可以更改此默认设置(但请务必了解您在做什么) 84Note that since the replica by default does not evict, it may end using more 85memory than the one set via maxmemory (there are certain buffers that may 86be larger on the replica, or data structures may sometimes take more memory 87and so forth). So make sure you monitor your replicas and make sure they 88have enough memory to never hit a real out-of-memory condition before the 89master hits the configured maxmemory setting. 90# 请注意,由于默认情况下该副本不会退出,因此它可能会结束使用比通过maxmemory设置的内存更多的内存(某些缓冲区在副本上可能会更大,或者数据结构有时会占用更多的内存,依此类推)。因此,请确保您监视副本,并确保副本具有足够的内存,以便在主副本达到配置的最大内存设置之前永远不会遇到真正的内存不足情况 91replica-ignore-maxmemory yes 92 93Redis reclaims expired keys in two ways: upon access when those keys are 94found to be expired, and also in background, in what is called the 95"active expire key". The key space is slowly and interactively scanned 96looking for expired keys to reclaim, so that it is possible to free memory 97of keys that are expired and will never be accessed again in a short time. 98# Redis通过两种方式回收过期的密钥:访问时发现这些密钥已过期,以及在后台,称为“活动的过期密钥”。缓慢地,交互地扫描密钥空间,以查找要回收的过期密钥,以便可以释放已过期且不久之后将不再访问的密钥的内存 99The default effort of the expire cycle will try to avoid having more than 100ten percent of expired keys still in memory, and will try to avoid consuming 101more than 25% of total memory and to add latency to the system. However 102it is possible to increase the expire "effort" that is normally set to 103"1", to a greater value, up to the value "10". At its maximum value the 104system will use more CPU, longer cycles (and technically may introduce 105more latency), and will tolerate less already expired keys still present 106in the system. It's a tradeoff between memory, CPU and latency. 107# 到期周期的默认工作将尝试避免在内存中保留超过百分之十的过期密钥,并且将尝试避免消耗超过总内存的25%并增加系统延迟。但是,可以将通常设置为“ 1”的过期“努力”增加到更大的值,直到值“ 10”。系统将以其最大值使用更多的CPU,更长的周期(并且从技术上讲可能会引入更多的延迟),并且将容忍更少的系统中仍然存在的已过期密钥。在内存,CPU和延迟之间进行权衡 108active-expire-effort 1
LRU是Least Recently Used的缩写,即最近最少使用
LFU(Least Frequently Used ,最近最少使用算法)也是一种常见的缓存算法
maxmemory:设置Redis的最大内存,如果设置为0 。表示不作限制。通常是配合下面介绍的maxmemory-policy参数一起使用。
maxmemory-policy :当内存使用达到maxmemory设置的最大值时,redis使用的内存清除策略。有以下几种可以选择:
1)volatile-lru 利用LRU算法移除设置过过期时间的key
2)allkeys-lru 利用LRU算法移除任何key
3)volatile-random 移除设置过过期时间的随机key
4)allkeys-random 移除随机ke
5)volatile-ttl 移除即将过期的key(minor TTL)
6)noeviction noeviction 不移除任何key,只是返回一个写错误 ,默认选项
maxmemory-samples :LRU 和 minimal TTL 算法都不是精准的算法,但是相对精确的算法(为了节省内存)。随意你可以选择样本大小进行检,redis默认选择5个样本进行检测,你可以通过maxmemory-samples进行设置样本数。
LAZY FREEING
1LAZY FREEING 2 3Redis has two primitives to delete keys. One is called DEL and is a blocking 4deletion of the object. It means that the server stops processing new commands 5in order to reclaim all the memory associated with an object in a synchronous 6way. If the key deleted is associated with a small object, the time needed 7in order to execute the DEL command is very small and comparable to most other 8O(1) or O(log_N) commands in Redis. However if the key is associated with an 9aggregated value containing millions of elements, the server can block for 10a long time (even seconds) in order to complete the operation. 11# Redis有两个删除键的原语。一种称为DEL,它是对象的阻塞删除。这意味着服务器停止处理新命令,以便以同步方式回收与对象关联的所有内存。如果删除的键与一个小对象相关联,则执行DEL命令所需的时间非常短,可与Redis中的大多数其他O(1)或O(log_N)命令相提并论。但是,如果键与包含数百万个元素的聚合值相关联,则服务器可能会阻塞很长时间(甚至几秒钟)以完成操作 12For the above reasons Redis also offers non blocking deletion primitives 13such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and 14FLUSHDB commands, in order to reclaim memory in background. Those commands 15are executed in constant time. Another thread will incrementally free the 16object in the background as fast as possible. 17# 由于上述原因,Redis还提供了非阻塞删除原语,例如UNLINK(非阻塞DEL)以及FLUSHALL和FLUSHDB命令的ASYNC选项,以便在后台回收内存。这些命令在固定时间内执行。另一个线程将尽可能快地在后台逐渐释放对象 18DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled. 19It's up to the design of the application to understand when it is a good 20idea to use one or the other. However the Redis server sometimes has to 21delete keys or flush the whole database as a side effect of other operations. 22Specifically Redis deletes objects independently of a user call in the 23following scenarios: 24# 用户可以控制FLUSHALL和FLUSHDB的DEL,UNLINK和ASYNC选项。由应用程序的设计来决定何时使用一个或另一个是一个好主意。但是,Redis服务器有时必须删除键或刷新整个数据库,这是其他操作的副作用。特别是在以下情况下,Redis会独立于用户调用而删除对象 251) On eviction, because of the maxmemory and maxmemory policy configurations, 26in order to make room for new data, without going over the specified 27memory limit. 282) Because of expire: when a key with an associated time to live (see the 29EXPIRE command) must be deleted from memory. 303) Because of a side effect of a command that stores data on a key that may 31already exist. For example the RENAME command may delete the old key 32content when it is replaced with another one. Similarly SUNIONSTORE 33or SORT with STORE option may delete existing keys. The SET command 34itself removes any old content of the specified key in order to replace 35it with the specified string. 364) During replication, when a replica performs a full resynchronization with 37its master, the content of the whole database is removed in order to 38load the RDB file just transferred. 39 40In all the above cases the default is to delete objects in a blocking way, 41like if DEL was called. However you can configure each case specifically 42in order to instead release memory in a non-blocking way like if UNLINK 43was called, using the following configuration directives. 44# 在上述所有情况下,默认设置都是以阻塞方式删除对象,就像调用DEL一样。但是,可以使用以下配置指令专门配置每种情况,以便以非阻塞方式释放内存,例如是否调用了UNLINK。 45lazyfree-lazy-eviction no 46lazyfree-lazy-expire no 47lazyfree-lazy-server-del no 48replica-lazy-flush no 49 50It is also possible, for the case when to replace the user code DEL calls 51with UNLINK calls is not easy, to modify the default behavior of the DEL 52command to act exactly like UNLINK, using the following configuration 53directive: 54# 对于用UNLINK调用替换用户代码DEL调用不容易的情况,也可以使用以下配置指令将DEL命令的默认行为修改为与UNLINK完全一样 55lazyfree-lazy-user-del no
THREADED I/O
1THREADED I/O 2 3Redis is mostly single threaded, however there are certain threaded 4operations such as UNLINK, slow I/O accesses and other things that are 5performed on side threads. 6# Redis大多是单线程的,但是有一些线程操作,例如UNLINK,缓慢的IO访问和其他在侧线程上执行的操作 7Now it is also possible to handle Redis clients socket reads and writes 8in different I/O threads. Since especially writing is so slow, normally 9Redis users use pipelining in order to speed up the Redis performances per 10core, and spawn multiple instances in order to scale more. Using I/O 11threads it is possible to easily speedup two times Redis without resorting 12to pipelining nor sharding of the instance. 13# 现在,还可以在不同的IO线程中处理Redis客户端套接字的读写。由于特别慢的写入速度,通常Redis用户使用流水线来加快每个内核的Redis性能,并生成多个实例以扩展规模。使用IO线程,可以轻松地将Redis加速两次,而无需求助于实例的流水线处理或分片 14By default threading is disabled, we suggest enabling it only in machines 15that have at least 4 or more cores, leaving at least one spare core. 16Using more than 8 threads is unlikely to help much. We also recommend using 17threaded I/O only if you actually have performance problems, with Redis 18instances being able to use a quite big percentage of CPU time, otherwise 19there is no point in using this feature. 20# 默认情况下,线程是禁用的,我们建议仅在具有至少4个或更多内核的计算机上启用它,而至少保留一个备用内核。使用8个以上的线程不太可能有很大帮助。我们还建议仅在实际存在性能问题时才使用线程IO,Redis实例可以使用很大一部分CPU时间,否则使用此功能毫无意义。 21So for instance if you have a four cores boxes, try to use 2 or 3 I/O 22threads, if you have a 8 cores, try to use 6 threads. In order to 23enable I/O threads use the following configuration directive: 24# 因此,例如,如果您有四个核的盒子,请尝试使用2个或3个IO线程,如果您有8个核,请尝试使用6个线程。为了启用IO线程,请使用以下配置指令 25io-threads 4 26 27Setting io-threads to 1 will just use the main thread as usual. 28When I/O threads are enabled, we only use threads for writes, that is 29to thread the write(2) syscall and transfer the client buffers to the 30socket. However it is also possible to enable threading of reads and 31protocol parsing using the following configuration directive, by setting 32it to yes: 33# 将io-threads设置为1只会照常使用主线程。启用IO线程后,我们仅使用线程进行写操作,即对write(2)系统调用进行线程化,并将客户端缓冲区传输到套接字。但是,也可以使用以下配置指令,通过将其设置为yes,来启用读取线程和协议解析 34io-threads-do-reads no 35 36Usually threading reads doesn't help much. 37# 通常线程读取并没有多大帮助 38NOTE 1: This configuration directive cannot be changed at runtime via 39CONFIG SET. Aso this feature currently does not work when SSL is 40enabled. 41# 注意1:无法在运行时通过CONFIG SET更改此配置指令。启用SSL后,该功能目前也无法使用。 42NOTE 2: If you want to test the Redis speedup using redis-benchmark, make 43sure you also run the benchmark itself in threaded mode, using the 44--threads option to match the number of Redis threads, otherwise you'll not 45be able to notice the improvements. 46# 注意2:如果要使用redis-benchmark测试Redis加速,请确保还使用--threads选项匹配Redis线程数,在线程模式下运行基准测试本身,否则将无法注意改进
KERNEL OOM CONTROL
1KERNEL OOM CONTROL # 内核OOM控制 2 3On Linux, it is possible to hint the kernel OOM killer on what processes 4should be killed first when out of memory. 5# 在Linux上,可以向内核OOM杀手提示内存不足时应首先终止哪些进程 6Enabling this feature makes Redis actively control the oom_score_adj value 7for all its processes, depending on their role. The default scores will 8attempt to have background child processes killed before all others, and 9replicas killed before masters. 10# 启用此功能可使Redis根据其进程主动控制其所有进程的oom_score_adj值。默认分数将尝试使后台子进程在所有其他进程之前被杀死,副本在主数据库之前被杀死 11oom-score-adj no 12 13When oom-score-adj is used, this directive controls the specific values used 14for master, replica and background child processes. Values range -1000 to 151000 (higher means more likely to be killed). 16# 使用oom-score-adj时,此伪指令控制用于主,副本和后台子进程的特定值。值范围-1000至1000(值越高,表示被杀死的可能性越高) 17Unprivileged processes (not root, and without CAP_SYS_RESOURCE capabilities) 18can freely increase their value, but not decrease it below its initial 19settings. 20# 无特权的进程(不是root进程,并且没有CAP_SYS_RESOURCE功能)可以自由地增加其值,但不能将其降低到其初始设置以下 21Values are used relative to the initial value of oom_score_adj when the server 22starts. Because typically the initial value is 0, they will often match the 23absolute values. 24 25oom-score-adj-values 0 200 800
APPEND ONLY MODE(重要)
1APPEND ONLY MODE 2 3By default Redis asynchronously dumps the dataset on disk. This mode is 4good enough in many applications, but an issue with the Redis process or 5a power outage may result into a few minutes of writes lost (depending on 6the configured save points). 7# 服务器启动时,使用相对于oom_score_adj初始值的值。因为通常初始值为0,所以它们通常会与绝对值匹配。 8The Append Only File is an alternative persistence mode that provides 9much better durability. For instance using the default data fsync policy 10(see later in the config file) Redis can lose just one second of writes in a 11dramatic event like a server power outage, or a single write if something 12wrong with the Redis process itself happens, but the operating system is 13still running correctly. 14# 仅附加文件是一种替代的持久性模式,可提供更好的持久性。例如,使用默认数据fsync策略(请参阅配置文件中的稍后内容),Redis在严重的事件(例如服务器断电)中仅会丢失一秒钟的写入,如果Redis进程本身发生问题,则可能会丢失一次写入,但是操作系统仍在正常运行 15AOF and RDB persistence can be enabled at the same time without problems. 16If the AOF is enabled on startup Redis will load the AOF, that is the file 17with the better durability guarantees. 18# 可以同时启用AOF和RDB持久性,而不会出现问题。如果在启动时启用了AOF,则Redis将加载AOF,即具有更好持久性的文件 19Please check http://redis.io/topics/persistence for more information. 20 21appendonly no 22 23The name of the append only file (default: "appendonly.aof") 24 25appendfilename "appendonly.aof" 26 27The fsync() call tells the Operating System to actually write data on disk 28instead of waiting for more data in the output buffer. Some OS will really flush 29data on disk, some other OS will just try to do it ASAP. 30# fsync()调用告诉操作系统将数据实际写入磁盘,而不是等待输出缓冲区中的更多数据。某些操作系统确实会刷新磁盘上的数据,而另一些操作系统会尽快尝试 31Redis supports three different modes: 32 33no: don't fsync, just let the OS flush the data when it wants. Faster. 34always: fsync after every write to the append only log. Slow, Safest. 35everysec: fsync only one time every second. Compromise. 36 37The default is "everysec", as that's usually the right compromise between 38speed and data safety. It's up to you to understand if you can relax this to 39"no" that will let the operating system flush the output buffer when 40it wants, for better performances (but if you can live with the idea of 41some data loss consider the default persistence mode that's snapshotting), 42or on the contrary, use "always" that's very slow but a bit safer than 43everysec. 44 45More details please check the following article: 46http://antirez.com/post/redis-persistence-demystified.html 47 48If unsure, use "everysec". 49 50appendfsync always 51appendfsync everysec 52appendfsync no 53 54When the AOF fsync policy is set to always or everysec, and a background 55saving process (a background save or AOF log background rewriting) is 56performing a lot of I/O against the disk, in some Linux configurations 57Redis may block too long on the fsync() call. Note that there is no fix for 58this currently, as even performing fsync in a different thread will block 59our synchronous write(2) call. 60# 当AOF fsync策略设置为always或everysec,并且后台保存进程(后台保存或AOF日志后台重写)对磁盘执行大量IO时,在某些Linux配置中,Redis可能会在fsync上阻塞太长时间( )致电。请注意,目前尚无此修复程序,因为即使在其他线程中执行fsync也将阻塞我们的同步write(2)调用 61In order to mitigate this problem it's possible to use the following option 62that will prevent fsync() from being called in the main process while a 63BGSAVE or BGREWRITEAOF is in progress. 64# 为了减轻此问题,可以使用以下选项来防止在BGSAVE或BGREWRITEAOF进行时在主进程中调用fsync() 65This means that while another child is saving, the durability of Redis is 66the same as "appendfsync none". In practical terms, this means that it is 67possible to lose up to 30 seconds of log in the worst scenario (with the 68default Linux settings). 69# 这意味着当另一个子线程正在保存时,Redis的持久性与“ appendfsync none”相同。实际上,这意味着在最坏的情况下(使用默认的Linux设置)可能会丢失多达30秒的日志 70If you have latency problems turn this to "yes". Otherwise leave it as 71"no" that is the safest pick from the point of view of durability. 72# 如果您有延迟问题,请将其设置为“是”。否则,从耐用性的角度出发,将其保留为“ no”是最安全的选择 73no-appendfsync-on-rewrite no 74 75Automatic rewrite of the append only file. 76Redis is able to automatically rewrite the log file implicitly calling 77BGREWRITEAOF when the AOF log size grows by the specified percentage. 78# 自动重写仅附加文件。当AOF日志大小增加指定百分比时,Redis能够自动重写日志文件,隐式调用BGREWRITEAOF 79This is how it works: Redis remembers the size of the AOF file after the 80latest rewrite (if no rewrite has happened since the restart, the size of 81the AOF at startup is used). 82# 它是这样工作的:Redis在最近一次重写之后会记住AOF文件的大小(如果自重新启动以来未发生任何重写,则使用启动时AOF的大小)。 83This base size is compared to the current size. If the current size is 84bigger than the specified percentage, the rewrite is triggered. Also 85you need to specify a minimal size for the AOF file to be rewritten, this 86is useful to avoid rewriting the AOF file even if the percentage increase 87is reached but it is still pretty small. 88# 将此基本大小与当前大小进行比较。如果当前大小大于指定的百分比,则触发重写。另外,您需要指定要重写的AOF文件的最小大小,这对于避免重写AOF文件很有用,即使达到百分比增加,但它仍然很小 89Specify a percentage of zero in order to disable the automatic AOF 90rewrite feature. 91# 指定零百分比以禁用自动AOF重写功能 92auto-aof-rewrite-percentage 100 93auto-aof-rewrite-min-size 64mb 94 95An AOF file may be found to be truncated at the end during the Redis 96startup process, when the AOF data gets loaded back into memory. 97This may happen when the system where Redis is running 98crashes, especially when an ext4 filesystem is mounted without the 99data=ordered option (however this can't happen when Redis itself 100crashes or aborts but the operating system still works correctly). 101# 当AOF数据重新加载回内存时,在Redis启动过程中可能会发现AOF文件在末尾被截断。当运行Redis的系统崩溃时,尤其是在没有data = ordered选项的情况下挂载ext4文件系统时,可能会发生这种情况(但是,当Redis本身崩溃或中止,但操作系统仍然可以正常运行时,就不会发生这种情况) 102Redis can either exit with an error when this happens, or load as much 103data as possible (the default now) and start if the AOF file is found 104to be truncated at the end. The following option controls this behavior. 105# 发生这种情况时,Redis可能会退出并显示错误,也可以加载尽可能多的数据(当前为默认值),如果发现AOF文件最后被截断,则Redis会开始。以下选项控制此行为 106If aof-load-truncated is set to yes, a truncated AOF file is loaded and 107the Redis server starts emitting a log to inform the user of the event. 108Otherwise if the option is set to no, the server aborts with an error 109and refuses to start. When the option is set to no, the user requires 110to fix the AOF file using the "redis-check-aof" utility before to restart 111the server. 112# 如果aof-load-truncated设置为yes,则将加载截短的AOF文件,并且Redis服务器将开始发出日志以将事件通知用户。否则,如果该选项设置为no,则服务器将中止并显示错误并拒绝启动。如果该选项设置为no,则用户需要在重新启动服务器之前使用“ redis-check-aof”实用程序修复AOF文件 113Note that if the AOF file will be found to be corrupted in the middle 114the server will still exit with an error. This option only applies when 115Redis will try to read more data from the AOF file but not enough bytes 116will be found. 117# 请注意,如果在中间发现AOF文件已损坏,则服务器仍将退出并出现错误。仅当Redis尝试从AOF文件读取更多数据但找不到足够的字节时,此选项才适用。 118aof-load-truncated yes 119 120When rewriting the AOF file, Redis is able to use an RDB preamble in the 121AOF file for faster rewrites and recoveries. When this option is turned 122on the rewritten AOF file is composed of two different stanzas: 123# 重写AOF文件时,Redis可以使用AOF文件中的RDB前同步码来更快地进行重写和恢复。启用此选项后,重写的AOF文件由两个不同的节组成 124[RDB file] [AOF tail] 125 126When loading, Redis recognizes that the AOF file starts with the "REDIS" 127string and loads the prefixed RDB file, then continues loading the AOF 128tail. 129# 加载时,Redis会识别AOF文件以“ REDIS”字符串开头并加载带前缀的RDB文件,然后继续加载AOF尾部。 130aof-use-rdb-preamble yes 131
appendonly(AOF)是一种替代的持久性模式,可提供更好的持久性。例如,使用默认数据fsync策略(请参阅配置文件中的稍后内容),Redis在严重的事件(例如服务器断电)中仅会丢失一秒钟的写入,如果Redis进程本身发生问题,则可能会丢失一次写入,但是操作系统仍在正常运行
可以同时启用AOF和RDB持久性,而不会出现问题。如果在启动时启用了AOF,则Redis将加载AOF,即具有更好持久性的文件
appendonly(AOF)默认是关闭的,我们可以appendonly yes
打开,默认文件名为appendonly.aof
默认redis使用的是rdb方式持久化,这种方式在许多应用中已经足够用了。但是redis如果中途宕机,会导致可能有几分钟的数据丢失,根据save来策略进行持久化,Append Only File是另一种持久化方式, 可以提供更好的持久化特性。Redis会把每次写入的数据在接收后都写入appendonly.aof文件,每次启动时Redis都会先把这个文件的数据读入内存里,先忽略RDB文件。默认值为no
appendonly(AOF)的启动参数有三个:默认使用appendfsync everysec
appendfsync always
appendfsync everysec
appendfsync no
aof持久化策略的配置;no表示不执行fsync,由操作系统保证数据同步到磁盘,速度最快;always表示每次写入都执行fsync,以保证数据同步到磁盘;everysec表示每秒执行一次fsync,可能会导致丢失这1s数据
在aof重写或者写入rdb文件的时候,会执行大量IO,此时对于everysec和always的aof模式来说,执行fsync会造成阻塞过长时间,no-appendfsync-on-rewrite字段设置为默认设置为no。如果对延迟要求很高的应用,这个字段可以设置为yes,否则还是设置为no,这样对持久化特性来说这是更安全的选择。设置为yes表示rewrite期间对新写操作不fsync,暂时存在内存中,等rewrite完成后再写入,默认为no,建议yes。Linux的默认fsync策略是30秒。可能丢失30秒数据。默认值为no。
如果您有延迟问题,请将其设置为“是”。否则,从耐用性的角度出发,将其保留为“ no”是最安全的选择
auto-aof-rewrite-percentage:默认值为100。aof自动重写配置,当目前aof文件大小超过上一次重写的aof文件大小的百分之多少进行重写,即当aof文件增长到一定大小的时候,Redis能够调用bgrewriteaof对日志文件进行重写。当前AOF文件大小是上次日志重写得到AOF文件大小的二倍(设置为100)时,自动启动新的日志重写过程。
auto-aof-rewrite-min-size:64mb。设置允许重写的最小aof文件大小,避免了达到约定百分比但尺寸仍然很小的情况还要重写。
aof-load-truncated:aof文件可能在尾部是不完整的,当redis启动的时候,aof文件的数据被载入内存。重启可能发生在redis所在的主机操作系统宕机后,尤其在ext4文件系统没有加上data=ordered选项,出现这种现象 redis宕机或者异常终止不会造成尾部不完整现象,可以选择让redis退出,或者导入尽可能多的数据。如果选择的是yes,当截断的aof文件被导入的时候,会自动发布一个log给客户端然后load。如果是no,用户必须手动redis-check-aof修复AOF文件才可以。默认值为 yes
LUA SCRIPTING
1LUA SCRIPTING 2 3Max execution time of a Lua script in milliseconds. 4# Lua脚本的最大执行时间(以毫秒为单位)。 5If the maximum execution time is reached Redis will log that a script is 6still in execution after the maximum allowed time and will start to 7reply to queries with an error. 8# 如果达到了最大执行时间,Redis将记录脚本在允许的最大时间后仍在执行中,并将开始以错误答复查询 9When a long running script exceeds the maximum execution time only the 10SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be 11used to stop a script that did not yet call any write commands. The second 12is the only way to shut down the server in the case a write command was 13already issued by the script but the user doesn't want to wait for the natural 14termination of the script. 15# 如果长时间运行的脚本超过了最大执行时间,则只有“ SCRIPT KILL”和“ SHUTDOWN NOSAVE”命令可用。第一个可用于停止尚未调用任何写命令的脚本。第二种是在脚本已经发出写命令但用户不想等待脚本自然终止的情况下关闭服务器的唯一方法 16Set it to 0 or a negative value for unlimited execution without warnings. 17# 将其设置为0或负值可无警告地无限执行 18lua-time-limit 5000
lua-time-limit:一个lua脚本执行的最大时间,单位为ms。默认值为5000
REDIS CLUSTER(重要)
1REDIS CLUSTER 2 3Normal Redis instances can't be part of a Redis Cluster; only nodes that are 4started as cluster nodes can. In order to start a Redis instance as a 5cluster node enable the cluster support uncommenting the following: 6# 普通Redis实例不能属于Redis集群;只有作为群集节点启动的节点可以。为了将Redis实例启动为集群节点,请启用集群支持 7cluster-enabled yes 8 9Every cluster node has a cluster configuration file. This file is not 10intended to be edited by hand. It is created and updated by Redis nodes. 11Every Redis Cluster node requires a different cluster configuration file. 12Make sure that instances running in the same system do not have 13overlapping cluster configuration file names. 14# 每个群集节点都有一个群集配置文件。该文件不适合手工编辑。它由Redis节点创建和更新。每个Redis群集节点都需要一个不同的群集配置文件。确保在同一系统上运行的实例没有重叠的集群配置文件名 15cluster-config-file nodes-6379.conf 16 17Cluster node timeout is the amount of milliseconds a node must be unreachable 18for it to be considered in failure state. 19Most other internal time limits are a multiple of the node timeout. 20# 群集节点超时是一个节点必须不可达的毫秒数,才能将其视为故障状态。其他大多数内部时间限制是节点超时的倍数 21cluster-node-timeout 15000 22 23A replica of a failing master will avoid to start a failover if its data 24looks too old. 25# 如果发生故障的主副本的数据看起来太旧,它将避免启动故障转移。 26There is no simple way for a replica to actually have an exact measure of 27its "data age", so the following two checks are performed: 28# 没有一种简单的方法可以使副本实际上具有其“数据年龄”的准确度量,因此执行以下两项检查 291) If there are multiple replicas able to failover, they exchange messages 30in order to try to give an advantage to the replica with the best 31replication offset (more data from the master processed). 32Replicas will try to get their rank by offset, and apply to the start 33of the failover a delay proportional to their rank. 34# # 如果存在多个能够进行故障转移的副本,则它们会交换消息,以便尝试利用具有最佳复制偏移量的副本(已处理来自主数据库的更多数据)来获得优势。副本将尝试按偏移量获得其排名,并将故障切换延迟按其排名成比例地应用于故障转移的开始 352) Every single replica computes the time of the last interaction with 36its master. This can be the last ping or command received (if the master 37is still in the "connected" state), or the time that elapsed since the 38disconnection with the master (if the replication link is currently down). 39If the last interaction is too old, the replica will not try to failover 40at all. 41# 每个单个副本都会计算与其主副本之间最后一次交互的时间。这可以是最后收到的ping或命令(如果主服务器仍处于“已连接”状态),也可以是自从与主服务器断开连接以来经过的时间(如果复制链接当前已关闭)。如果最后一次交互太旧,则副本将完全不会尝试故障转移 42The point "2" can be tuned by user. Specifically a replica will not perform 43the failover if, since the last interaction with the master, the time 44elapsed is greater than: 45# 用户可以调整点“ 2”。特别是,如果自从上次与主服务器进行交互以来,如果经过的时间大于或等于一个副本,则副本将不执行故障转移。 46(node-timeout * cluster-replica-validity-factor) + repl-ping-replica-period 47# (节点超时 * 集群副本有效性因子)+ 复制周期 48So for example if node-timeout is 30 seconds, and the cluster-replica-validity-factor 49is 10, and assuming a default repl-ping-replica-period of 10 seconds, the 50replica will not try to failover if it was not able to talk with the master 51for longer than 310 seconds. 52# 因此,例如,如果节点超时为30秒,并且集群副本有效期因子为10,并且假设默认的repl-ping-replica-period为10秒,则副本将无法尝试进行故障转移,如果它不能与主人交谈超过310秒 53A large cluster-replica-validity-factor may allow replicas with too old data to failover 54a master, while a too small value may prevent the cluster from being able to 55elect a replica at all. 56# 较大的群集副本有效性因素可能会使数据过旧的副本无法对主副本进行故障转移,而值太小可能会使群集根本无法选择副本 57For maximum availability, it is possible to set the cluster-replica-validity-factor 58to a value of 0, which means, that replicas will always try to failover the 59master regardless of the last time they interacted with the master. 60(However they'll always try to apply a delay proportional to their 61offset rank). 62# 为了获得最大可用性,可以将cluster-replica-validity-factor设置为0,这意味着,无论副本上次与主服务器交互是什么,副本将始终尝试对主服务器进行故障转移。 (但是,他们将始终尝试按与其偏移等级成比例的方式应用延迟) 63Zero is the only value able to guarantee that when all the partitions heal 64the cluster will always be able to continue. 65# 零是唯一能够确保当所有分区恢复正常时群集将始终能够继续运行的值 66cluster-replica-validity-factor 10 67 68Cluster replicas are able to migrate to orphaned masters, that are masters 69that are left without working replicas. This improves the cluster ability 70to resist to failures as otherwise an orphaned master can't be failed over 71in case of failure if it has no working replicas. 72# 群集副本能够迁移到孤立的主数据库,即那些没有工作副本的主数据库。这提高了群集抵抗故障的能力,否则如果孤立的主节点没有可用的副本,则该主节点在发生故障的情况下无法进行故障转移 73Replicas migrate to orphaned masters only if there are still at least a 74given number of other working replicas for their old master. This number 75is the "migration barrier". A migration barrier of 1 means that a replica 76will migrate only if there is at least 1 other working replica for its master 77and so forth. It usually reflects the number of replicas you want for every 78master in your cluster. 79# 仅当旧的主副本仍存在至少给定数量的其他工作副本时,副本副本才会迁移到孤立的主副本。这个数字是“移民壁垒”。迁移屏障为1意味着,仅当副本数据库的主副本中至少有1个其他工作副本时,副本副本才会迁移。它通常反映出集群中每个主数据库所需的副本数 80Default is 1 (replicas migrate only if their masters remain with at least 81one replica). To disable migration just set it to a very large value. 82A value of 0 can be set but is useful only for debugging and dangerous 83in production. 84# 缺省值为1(仅当其主副本保留至少一个副本副本时,副本副本才会迁移)。要禁用迁移,只需将其设置为非常大的值即可。可以设置为0,但仅用于调试和生产危险 85cluster-migration-barrier 1 86 87By default Redis Cluster nodes stop accepting queries if they detect there 88is at least a hash slot uncovered (no available node is serving it). 89This way if the cluster is partially down (for example a range of hash slots 90are no longer covered) all the cluster becomes, eventually, unavailable. 91It automatically returns available as soon as all the slots are covered again. 92# 默认情况下,如果Redis Cluster节点检测到至少发现一个哈希槽(没有可用的节点正在为其提供服务),它们将停止接受查询。这样,如果集群部分关闭(例如,不再覆盖哈希槽范围),则所有集群最终将变得不可用。再次覆盖所有插槽后,它将自动返回可用状态 93However sometimes you want the subset of the cluster which is working, 94to continue to accept queries for the part of the key space that is still 95covered. In order to do so, just set the cluster-require-full-coverage 96option to no. 97# 但是,有时您希望正在运行的集群子集继续接受对仍覆盖的部分键空间的查询。为此,只需将cluster-require-full-coverage选项设置为no 98 99cluster-require-full-coverage yes 100 101This option, when set to yes, prevents replicas from trying to failover its 102master during master failures. However the master can still perform a 103manual failover, if forced to do so. 104# 设置为yes时,此选项可防止副本在主服务器发生故障时尝试对其主服务器进行故障转移。但是,主服务器仍然可以执行手动故障转移(如果被迫执行) 105This is useful in different scenarios, especially in the case of multiple 106data center operations, where we want one side to never be promoted if not 107in the case of a total DC failure. 108# 这在不同的情况下很有用,尤其是在多个数据中心操作的情况下,在这种情况下,如果完全DC失败,我们希望不升级一侧。 109cluster-replica-no-failover no 110 111This option, when set to yes, allows nodes to serve read traffic while the 112the cluster is in a down state, as long as it believes it owns the slots. 113# 设置为yes时,此选项允许节点在群集处于关闭状态时为其提供读取流量,只要它认为自己拥有插槽即可 114This is useful for two cases. The first case is for when an application 115doesn't require consistency of data during node failures or network partitions. 116One example of this is a cache, where as long as the node has the data it 117should be able to serve it. 118# 这对于两种情况很有用。第一种情况是在节点故障或网络分区期间应用程序不需要数据一致性时。一个示例是高速缓存,只要节点具有数据,它就应该能够为其服务 119The second use case is for configurations that don't meet the recommended 120three shards but want to enable cluster mode and scale later. A 121master outage in a 1 or 2 shard configuration causes a read/write outage to the 122entire cluster without this option set, with it set there is only a write outage. 123Without a quorum of masters, slot ownership will not change automatically. 124# 第二个用例是针对不符合建议的三个分片但希望启用集群模式并在以后扩展的配置。如果没有设置此选项,则在1或2分片配置中的主服务器中断会导致整个集群的读写中断。如果没有法定人数的主持人,则插槽所有权不会自动更改 125cluster-allow-reads-when-down no 126 127In order to setup your cluster make sure to read the documentation 128available at http://redis.io web site.
cluster-enabled:集群开关,默认是不开启集群模式。
cluster-config-file:集群配置文件的名称,每个节点都有一个集群相关的配置文件,持久化保存集群的信息。这个文件并不需要手动配置,这个配置文件有Redis生成并更新,每个Redis集群节点需要一个单独的配置文件。请确保与实例运行的系统中配置文件名称不冲突。默认配置为nodes-6379.conf
cluster-node-timeout :可以配置值为15000。节点互连超时的阀值,集群节点超时毫秒数
cluster-slave-validity-factor :可以配置值为10。在进行故障转移的时候,全部slave都会请求申请为master,但是有些slave可能与master断开连接一段时间了, 导致数据过于陈旧,这样的slave不应该被提升为master。该参数就是用来判断slave节点与master断线的时间是否过长。
判断方法是:比较slave断开连接的时间和(node-timeout * slave-validity-factor) + repl-ping-slave-period 如果节点超时时间为三十秒, 并且slave-validity-factor为10,假设默认的repl-ping-slave-period是10秒,即如果超过310秒slave将不会尝试进行故障转移
cluster-migration-barrier :可以配置值为1。master的slave数量大于该值,slave才能迁移到其他孤立master上,如这个参数若被设为2,那么只有当一个主节点拥有2 个可工作的从节点时,它的一个从节点会尝试迁移。
cluster-require-full-coverage:默认情况下,集群全部的slot有节点负责,集群状态才为ok,才能提供服务。设置为no,可以在slot没有全部分配的时候提供服务。不建议打开该配置,这样会造成分区的时候,小分区的master一直在接受写请求,而造成很长时间数据不一致。
CLUSTER DOCKER/NAT support
1CLUSTER DOCKER/NAT support 2 3In certain deployments, Redis Cluster nodes address discovery fails, because 4addresses are NAT-ted or because ports are forwarded (the typical case is 5Docker and other containers). 6# 在某些部署中,Redis群集节点地址发现失败,这是因为地址经过NAT限制或端口已转发(典型情况是Docker和其他容器) 7In order to make Redis Cluster working in such environments, a static 8configuration where each node knows its public address is needed. The 9following two options are used for this scope, and are: 10# 为了使Redis Cluster在这样的环境中工作,需要一个静态配置,其中每个节点都知道其公共地址。以下两个选项用于此范围,分别是 11* cluster-announce-ip 12* cluster-announce-port 13* cluster-announce-bus-port 14 15Each instructs the node about its address, client port, and cluster message 16bus port. The information is then published in the header of the bus packets 17so that other nodes will be able to correctly map the address of the node 18publishing the information. 19# 每个节点都向节点指示其地址,客户端端口和群集消息总线端口。然后将信息发布在总线数据包的标题中,以便其他节点将能够正确映射发布信息的节点的地址 20If the above options are not used, the normal Redis Cluster auto-detection 21will be used instead. 22# 如果未使用上述选项,则将使用常规的Redis群集自动检测 23Note that when remapped, the bus port may not be at the fixed offset of 24clients port + 10000, so you can specify any port and bus-port depending 25on how they get remapped. If the bus-port is not set, a fixed offset of 2610000 will be used as usual. 27# 请注意,重新映射时,总线端口可能不在客户端端口+ 10000的固定偏移处,因此您可以根据重新映射的方式指定任何端口和总线端口。如果未设置总线端口,则将照常使用10000的固定偏移量 28Example: 29 30cluster-announce-ip 10.1.1.5 31cluster-announce-port 6379 32cluster-announce-bus-port 6380
在某些部署中,Redis群集节点寻址失败,这是因为地址经过NAT限制或端口已转发(典型情况是Docker和其他容器),为了使Redis Cluster在这样的环境中工作,需要一个静态配置,其中每个节点都知道其公共地址。以下两个选项用于此范围,分别是
- cluster-announce-ip
- cluster-announce-port
- cluster-announce-bus-port
SLOW LOG
1SLOW LOG 2 3The Redis Slow Log is a system to log queries that exceeded a specified 4execution time. The execution time does not include the I/O operations 5like talking with the client, sending the reply and so forth, 6but just the time needed to actually execute the command (this is the only 7stage of command execution where the thread is blocked and can not serve 8other requests in the meantime). 9# Redis Slow Log是一个用于记录超过指定执行时间的查询的系统。执行时间不包括与客户端交谈,发送回复等IO操作,而仅包括实际执行命令所需的时间(这是命令执行的唯一阶段,在该阶段线程被阻塞并且无法服务同时提出其他要求) 10You can configure the slow log with two parameters: one tells Redis 11what is the execution time, in microseconds, to exceed in order for the 12command to get logged, and the other parameter is the length of the 13slow log. When a new command is logged the oldest one is removed from the 14queue of logged commands. 15# 您可以使用以下两个参数配置慢速日志:一个告诉Redis,为了使命令被记录下来,执行时间要超过多少微秒,而另一个参数是慢速日志的长度。记录新命令时,最早的命令将从记录的命令队列中删除 16The following time is expressed in microseconds, so 1000000 is equivalent 17to one second. Note that a negative number disables the slow log, while 18a value of zero forces the logging of every command. 19# 时间以微秒为单位,因此1000000等于一秒。请注意,负数将禁用慢速日志记录,而零值将强制记录每个命令 20slowlog-log-slower-than 10000 21 22There is no limit to this length. Just be aware that it will consume memory. 23You can reclaim memory used by the slow log with SLOWLOG RESET. 24slowlog-max-len 128 25# 该长度没有限制。请注意,它将消耗内存。您可以使用SLOWLOG RESET回收慢日志使用的内存
Slowlog-log-slower-than: 默认值为10000,其中1000000等于1秒(负数将禁用慢速日志记录,而零值将强制记录每个命令)
slowlog-max-len: 日志的长度默认值为128,新日志将追加。就日志将从前删除。
LATENCY MONITOR
1LATENCY MONITOR 2 3The Redis latency monitoring subsystem samples different operations 4at runtime in order to collect data related to possible sources of 5latency of a Redis instance. 6# Redis延迟监视子系统在运行时对不同的操作进行采样,以便收集与Redis实例的潜在延迟源相关的数据 7Via the LATENCY command this information is available to the user that can 8print graphs and obtain reports. 9# 通过LATENCY命令,该信息可供打印,获取报告的用户使用 10The system only logs operations that were performed in a time equal or 11greater than the amount of milliseconds specified via the 12latency-monitor-threshold configuration directive. When its value is set 13to zero, the latency monitor is turned off. 14# 系统仅记录在等于或大于通过delay-monitor-threshold配置指令指定的毫秒量的时间内执行的操作。当其值设置为零时,等待时间监视器将关闭 15By default latency monitoring is disabled since it is mostly not needed 16if you don't have latency issues, and collecting data has a performance 17impact, that while very small, can be measured under big load. Latency 18monitoring can easily be enabled at runtime using the command 19"CONFIG SET latency-monitor-threshold <milliseconds>" if needed. 20# 默认情况下,延迟监视是禁用的,因为如果您没有延迟问题,通常不需要它,并且收集数据会对性能产生影响,尽管影响很小,但是可以在大负载下进行测量。如果需要,可以在运行时使用命令“ CONFIG SET delay-monitor-threshold <milliseconds>”轻松启用延迟监视 21latency-monitor-threshold 0
EVENT NOTIFICATION
1EVENT NOTIFICATION 2 3Redis can notify Pub/Sub clients about events happening in the key space. 4This feature is documented at http://redis.io/topics/notifications 5# Redis可以通知PubSub客户端关键空间中发生的事件 6For instance if keyspace events notification is enabled, and a client 7performs a DEL operation on key "foo" stored in the Database 0, two 8messages will be published via Pub/Sub: 9# 例如,如果启用了键空间事件通知,并且客户端对存储在数据库0中的键“ foo”执行了DEL操作,则将通过PubSub发布两条消息 10PUBLISH __keyspace@0__:foo del 11PUBLISH __keyevent@0__:del foo 12 13It is possible to select the events that Redis will notify among a set 14of classes. Every class is identified by a single character: 15# 可以在一组类中选择Redis将通知的事件。每个类别都由单个字符标识 16K Keyspace events, published with __keyspace@<db>__ prefix. # 空键事件,以__keyspace @ <db> __前缀发布 17E Keyevent events, published with __keyevent@<db>__ prefix. # 按键事件,以__keyevent @ <db> __前缀发布 18g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ... # 通用命令(非类型专用),例如DEL,EXPIRE,RENAME 19$ String commands # 字符串命令 20l List commands # 列表命令 21s Set commands # 集合命令 22h Hash commands # 哈希命令 23z Sorted set commands # 有序集合命令 24x Expired events (events generated every time a key expires) # 过期事件(每次密钥过期时生成的事件) 25e Evicted events (events generated when a key is evicted for maxmemory) # 驱逐事件(将密钥驱逐到最大内存时生成的事件) 26t Stream commands # 流命令 27m Key-miss events (Note: It is not included in the 'A' class) # 键丢失事件(注意:它不包含在“ A”类中) 28A Alias for g$lshzxet, so that the "AKE" string means all the events # glshzxet的别名,因此“ AKE”字符串表示所有事件 29 (Except key-miss events which are excluded from 'A' due to their 30 unique nature). 31 32The "notify-keyspace-events" takes as argument a string that is composed 33of zero or multiple characters. The empty string means that notifications 34are disabled. 35# “ notify-keyspace-events”将由零个或多个字符组成的字符串作为参数。空字符串表示已禁用通知 36Example: to enable list and generic events, from the point of view of the 37 event name, use: 38 39notify-keyspace-events Elg 40 41Example 2: to get the stream of the expired keys subscribing to channel 42 name __keyevent@0__:expired use: 43 44notify-keyspace-events Ex 45 46By default all notifications are disabled because most users don't need 47this feature and the feature has some overhead. Note that if you don't 48specify at least one of K or E, no events will be delivered. 49notify-keyspace-events "" 50# 默认情况下,所有通知都被禁用,因为大多数用户不需要此功能,并且该功能有一些开销。请注意,如果您未指定K或E中的至少一个,则不会传递任何事件。notify-keyspace-events
GOPHER SERVER
1GOPHER SERVER 2 3Redis contains an implementation of the Gopher protocol, as specified in 4the RFC 1436 (https://www.ietf.org/rfc/rfc1436.txt). 5# Redis包含RFC 1436(https:www.ietf.orgrfcrfc1436.txt)中指定的Gopher协议的实现。 6The Gopher protocol was very popular in the late '90s. It is an alternative 7to the web, and the implementation both server and client side is so simple 8that the Redis server has just 100 lines of code in order to implement this 9support. 10# Gopher协议在90年代后期非常流行。它是Web的替代方法,服务器和客户端的实现是如此简单,以至于Redis服务器只有100行代码才能实现这种支持 11What do you do with Gopher nowadays? Well Gopher never *really* died, and 12lately there is a movement in order for the Gopher more hierarchical content 13composed of just plain text documents to be resurrected. Some want a simpler 14internet, others believe that the mainstream internet became too much 15controlled, and it's cool to create an alternative space for people that 16want a bit of fresh air. 17# 您现在如何使用Gopher?好吧,Gopher从未真正死过,最近出现了一种运动,目的是使Gopher具有更多层次的内容(由纯文本文档组成)得以复活。有些人想要一个更简单的互联网,另一些人则认为主流互联网变得过于受控,为想要一点新鲜空气的人们创造一个替代空间很酷。 18Anyway for the 10nth birthday of the Redis, we gave it the Gopher protocol 19as a gift. 20# 无论如何,在Redis十岁生日的时候,我们给了它Gopher协议作为礼物 21--- HOW IT WORKS? --- 22 23The Redis Gopher support uses the inline protocol of Redis, and specifically 24two kind of inline requests that were anyway illegal: an empty request 25or any request that starts with "/" (there are no Redis commands starting 26with such a slash). Normal RESP2/RESP3 requests are completely out of the 27path of the Gopher protocol implementation and are served as usual as well. 28# Redis Gopher支持使用Redis的内联协议,特别是两种仍然非法的内联请求:空请求或任何以“”开头的请求(没有以这样的斜杠开头的Redis命令)。正常的RESP2RESP3请求完全超出了Gopher协议实现的路径,并且也照常使用 29If you open a connection to Redis when Gopher is enabled and send it 30a string like "/foo", if there is a key named "/foo" it is served via the 31Gopher protocol. 32# 如果在启用Gopher时打开与Redis的连接,并向其发送“ foo”之类的字符串,则如果存在名为“ foo”的密钥,则会通过Gopher协议为其提供服务 33In order to create a real Gopher "hole" (the name of a Gopher site in Gopher 34talking), you likely need a script like the following: 35 36https://github.com/antirez/gopher2redis 37 38--- SECURITY WARNING --- 39 40If you plan to put Redis on the internet in a publicly accessible address 41to server Gopher pages MAKE SURE TO SET A PASSWORD to the instance. 42Once a password is set: 43 441. The Gopher server (when enabled, not by default) will still serve 45 content via Gopher. 462. However other commands cannot be called before the client will 47 authenticate. 48 49So use the 'requirepass' option to protect your instance. 50 51Note that Gopher is not currently supported when 'io-threads-do-reads' 52is enabled. 53 54To enable Gopher support, uncomment the following line and set the option 55from no (the default) to yes. 56 57gopher-enabled no
ADVANCED CONFIG
1ADVANCED CONFIG 2 3Hashes are encoded using a memory efficient data structure when they have a 4small number of entries, and the biggest entry does not exceed a given 5threshold. These thresholds can be configured using the following directives. 6# 当哈希条目只有少量条目且最大条目未超过给定阈值时,将使用内存高效的数据结构对其进行编码。可以使用以下指令配置这些阈值 7hash-max-ziplist-entries 512 8hash-max-ziplist-value 64 9 10Lists are also encoded in a special way to save a lot of space. 11The number of entries allowed per internal list node can be specified 12as a fixed maximum size or a maximum number of elements. 13# 列表也以特殊方式编码,以节省大量空间。每个内部列表节点允许的条目数可以指定为固定的最大大小或最大元素数 14For a fixed maximum size, use -5 through -1, meaning: 15# 对于固定的最大大小,请使用-5到-1,表示 16-5: max size: 64 Kb <-- not recommended for normal workloads 17-4: max size: 32 Kb <-- not recommended 18-3: max size: 16 Kb <-- probably not recommended 19-2: max size: 8 Kb <-- good 20-1: max size: 4 Kb <-- good 21Positive numbers mean store up to _exactly_ that number of elements 22per list node. 23# 正数表示每个列表节点最多可存储_exactly_个元素 24The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size), 25but if your use case is unique, adjust the settings as necessary. 26# 最高性能的选项通常是-2(8 Kb大小)或-1(4 Kb大小),但是如果您的用例是唯一的,请根据需要调整设置 27list-max-ziplist-size -2 28 29Lists may also be compressed. # 列表也可以被压缩。 30Compress depth is the number of quicklist ziplist nodes from *each* side of 31the list to *exclude* from compression. The head and tail of the list 32are always uncompressed for fast push/pop operations. Settings are: 33# 压缩深度是列表的每侧要从压缩中排除的快速列表ziplist节点的数量。列表的开头和结尾始终是未压缩的,以便快速进行pushpop操作。设置是 340: disable all list compression # 禁用所有列表压缩 351: depth 1 means "don't start compressing until after 1 node into the list, 36going from either the head or tail" # 深度1表示“直到列表中有1个节点之后,才开始压缩,从头到尾 37So: [head]->node->node->...->node->[tail] 38[head], [tail] will always be uncompressed; inner nodes will compress. 392: [head]->[next]->node->node->...->node->[prev]->[tail] 402 here means: don't compress head or head->next or tail->prev or tail, 41but compress all nodes between them. 423: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail] 43etc. 44list-compress-depth 0 45 46Sets have a special encoding in just one case: when a set is composed 47of just strings that happen to be integers in radix 10 in the range 48of 64 bit signed integers. 49The following configuration setting sets the limit in the size of the 50set in order to use this special memory saving encoding. 51# 在仅一种情况下,集合具有特殊的编码:当集合仅由恰好是基数10中整数(在64位有符号整数范围内)的字符串组成时。以下配置设置设置了大小限制,以便使用此特殊的内存节省编码 52set-max-intset-entries 512 53 54Similarly to hashes and lists, sorted sets are also specially encoded in 55order to save a lot of space. This encoding is only used when the length and 56elements of a sorted set are below the following limits: 57# 与哈希表和列表类似,对排序集也进行了特殊编码,以节省大量空间。仅当排序集的长度和元素低于以下限制时,才使用此编码 58zset-max-ziplist-entries 128 59zset-max-ziplist-value 64 60 61HyperLogLog sparse representation bytes limit. The limit includes the 6216 bytes header. When an HyperLogLog using the sparse representation crosses 63this limit, it is converted into the dense representation. 64# HyperLogLog稀疏表示形式的字节数限制。限制包括16个字节的标头。当使用稀疏表示的HyperLogLog超过此限制时,它将转换为密集表示 65A value greater than 16000 is totally useless, since at that point the 66dense representation is more memory efficient. 67# 大于16000的值是完全没有用的,因为在那一点上,密集表示的存储效率更高 68The suggested value is ~ 3000 in order to have the benefits of 69the space efficient encoding without slowing down too much PFADD, 70which is O(N) with the sparse encoding. The value can be raised to 71~ 10000 when CPU is not a concern, but space is, and the data set is 72composed of many HyperLogLogs with cardinality in the 0 - 15000 range. 73# 建议值约为3000,以便在不减慢过多PFADD的情况下获得节省空间编码的好处,而PFADD的稀疏编码为O(N)。当不关心CPU但有空间时,该值可以提高到10000,并且数据集由基数在0-15000范围内的许多HyperLogLog组成 74hll-sparse-max-bytes 3000 75 76Streams macro node max size / items. The stream data structure is a radix 77tree of big nodes that encode multiple items inside. Using this configuration 78it is possible to configure how big a single node can be in bytes, and the 79maximum number of items it may contain before switching to a new node when 80appending new stream entries. If any of the following settings are set to 81zero, the limit is ignored, so for instance it is possible to set just a 82max entires limit by setting max-bytes to 0 and max-entries to the desired 83value. 84# 流宏节点最大大小的项目。流数据结构是一个大节点的基数树,它对内部的多个项目进行编码。使用此配置,可以配置单个节点的大小(以字节为单位),以及在添加新的流条目时切换到新节点之前它可能包含的最大项目数。如果以下任何设置被设置为零,则该限制将被忽略,例如,可以通过将max-bytes设置为0并将max-entries设置为所需的值来仅设置最大整数限制 85stream-node-max-bytes 4096 86stream-node-max-entries 100 87 88Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in 89order to help rehashing the main Redis hash table (the one mapping top-level 90keys to values). The hash table implementation Redis uses (see dict.c) 91performs a lazy rehashing: the more operation you run into a hash table 92that is rehashing, the more rehashing "steps" are performed, so if the 93server is idle the rehashing is never complete and some more memory is used 94by the hash table. 95# 活动重新哈希处理每100毫秒CPU时间使用1毫秒,以帮助重新哈希主Redis哈希表(将顶级键映射到值的一个哈希表)。Redis使用的哈希表实现(请参阅dict.c)执行一次懒惰的重新哈希处理:您在要进行哈希处理的哈希表中运行的操作越多,执行的哈希处理“步骤”就越多,因此,如果服务器空闲,则哈希处理将永远不会完成哈希表使用了更多的内存 96The default is to use this millisecond 10 times every second in order to 97actively rehash the main dictionaries, freeing memory when possible. 98# 默认值是每秒使用10毫秒的毫秒数来主动重新哈希主字典,并在可能的情况下释放内存 99If unsure: 100use "activerehashing no" if you have hard latency requirements and it is 101not a good thing in your environment that Redis can reply from time to time 102to queries with 2 milliseconds delay. 103# 如果不确定:如果您有严格的延迟要求,则使用“ activehashing no”,并且在您的环境中,Redis可以不时地以2毫秒的延迟答复查询不是一件好事 104 105use "activerehashing yes" if you don't have such hard requirements but 106want to free memory asap when possible. 107# 如果您没有如此严格的要求,但想在可能的情况下尽快释放内存,请使用“ activerehashing yes” 108activerehashing yes 109 110The client output buffer limits can be used to force disconnection of clients 111that are not reading data from the server fast enough for some reason (a 112common reason is that a Pub/Sub client can't consume messages as fast as the 113publisher can produce them). 114# 客户端输出缓冲区限制可用于出于某些原因强制断开那些没有足够快地从服务器读取数据的客户端(常见原因是PubSub客户端不能像发布者产生消息那样快地消耗消息) 115The limit can be set differently for the three different classes of clients: 116# 可以为三种不同类别的客户设置不同的限制 117normal -> normal clients including MONITOR clients # 普通客户,包括MONITOR客户 118replica -> replica clients # 复制客户端 119pubsub -> clients subscribed to at least one pubsub channel or pattern # 客户订阅了至少一个pubsub频道或模式 120 121The syntax of every client-output-buffer-limit directive is the following: 122# 每个client-output-buffer-limit指令的语法如下 123client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds> 124 125A client is immediately disconnected once the hard limit is reached, or if 126the soft limit is reached and remains reached for the specified number of 127seconds (continuously). 128So for instance if the hard limit is 32 megabytes and the soft limit is 12916 megabytes / 10 seconds, the client will get disconnected immediately 130if the size of the output buffers reach 32 megabytes, but will also get 131disconnected if the client reaches 16 megabytes and continuously overcomes 132the limit for 10 seconds. 133# 一旦达到硬限制,或者达到软限制并在指定的秒数内(连续)保持达到此限制,客户端将立即断开连接。因此,例如,如果硬限制为32兆字节,软限制为16兆字节10秒,则如果输出缓冲区的大小达到32兆字节,客户端将立即断开连接,但是如果客户端达到16兆字节并连续不断,连接也会断开连接超过极限10秒 134By default normal clients are not limited because they don't receive data 135without asking (in a push way), but just after a request, so only 136asynchronous clients may create a scenario where data is requested faster 137than it can read. 138# 默认情况下,普通客户端不受限制,因为它们不会在不询问的情况下(以推送方式)接收数据,而是在请求之后才接收数据,因此,只有异步客户端才可能创建这样的场景:请求数据的速度比读取数据的速度快 139Instead there is a default limit for pubsub and replica clients, since 140subscribers and replicas receive data in a push fashion. 141# 而是对pubsub和副本客户端有默认限制,因为订阅者和副本以推送方式接收数据 142Both the hard or the soft limit can be disabled by setting them to zero. 143# 硬限制或软限制都可以通过将其设置为零来禁用 144client-output-buffer-limit normal 0 0 0 145client-output-buffer-limit replica 256mb 64mb 60 146client-output-buffer-limit pubsub 32mb 8mb 60 147 148Client query buffers accumulate new commands. They are limited to a fixed 149amount by default in order to avoid that a protocol desynchronization (for 150instance due to a bug in the client) will lead to unbound memory usage in 151the query buffer. However you can configure it here if you have very special 152needs, such us huge multi/exec requests or alike. 153# 客户端查询缓冲区会累积新命令。默认情况下,它们被限制为固定数量,以避免协议不同步(例如,由于客户端中的错误)将导致查询缓冲区中的未绑定内存使用。但是,如果您有非常特殊的需求(例如我们巨大的multiexec请求等),则可以在此处进行配置。 154client-query-buffer-limit 1gb 155 156In the Redis protocol, bulk requests, that are, elements representing single 157strings, are normally limited to 512 mb. However you can change this limit 158here, but must be 1mb or greater 159# 在Redis协议中,批量请求(即表示单个字符串的元素)通常限制为512 mb。但是,您可以在此处更改此限制,但必须为1mb或更大 160proto-max-bulk-len 512mb 161 162Redis calls an internal function to perform many background tasks, like 163closing connections of clients in timeout, purging expired keys that are 164never requested, and so forth. 165# Redis调用内部函数来执行许多后台任务,例如在超时时关闭客户端连接,清除从未请求的过期密钥等 166Not all tasks are performed with the same frequency, but Redis checks for 167tasks to perform according to the specified "hz" value. 168# 并非所有任务都以相同的频率执行,但是Redis会根据指定的“ hz”值检查要执行的任务 169By default "hz" is set to 10. Raising the value will use more CPU when 170Redis is idle, but at the same time will make Redis more responsive when 171there are many keys expiring at the same time, and timeouts may be 172handled with more precision. 173# 默认情况下,“ hz”设置为10。提高该值将在Redis空闲时使用更多的CPU,但是同时当有多个键同时到期时,它将使Redis的响应速度更快,并且可以使用更多的超时来处理精确 174The range is between 1 and 500, however a value over 100 is usually not 175a good idea. Most users should use the default of 10 and raise this up to 176100 only in environments where very low latency is required. 177# 范围在1到500之间,但是值通常不超过100。大多数用户应该使用默认值10,并且仅在要求非常低延迟的环境中才将其提高到100 178hz 10 179 180Normally it is useful to have an HZ value which is proportional to the 181number of clients connected. This is useful in order, for instance, to 182avoid too many clients are processed for each background task invocation 183in order to avoid latency spikes. 184# 通常,具有与连接的客户端数量成比例的HZ值很有用。例如,这有助于避免每次后台任务调用处理过多的客户端,从而避免延迟高峰 185Since the default HZ value by default is conservatively set to 10, Redis 186offers, and enables by default, the ability to use an adaptive HZ value 187which will temporarily raise when there are many connected clients. 188# 由于默认的默认HZ值保守地设置为10,因此Redis提供并默认启用了使用自适应HZ值的能力,当有许多连接的客户端时,该值会暂时升高 189When dynamic HZ is enabled, the actual configured HZ will be used 190as a baseline, but multiples of the configured HZ value will be actually 191used as needed once more clients are connected. In this way an idle 192instance will use very little CPU time while a busy instance will be 193more responsive. 194# 启用动态HZ后,实际配置的HZ将用作基准,但是一旦连接了更多客户端,实际将使用配置的HZ值的倍数。这样,空闲实例将占用很少的CPU时间,而忙碌的实例将具有更快的响应能力 195dynamic-hz yes 196 197When a child rewrites the AOF file, if the following option is enabled 198the file will be fsync-ed every 32 MB of data generated. This is useful 199in order to commit the file to the disk more incrementally and avoid 200big latency spikes. 201# 当孩子重写AOF文件时,如果启用了以下选项,则每生成32 MB的数据,文件就会进行同步处理。这对于将文件更多地提交到磁盘并避免大的延迟峰值很有用。 202aof-rewrite-incremental-fsync yes 203 204When redis saves RDB file, if the following option is enabled 205the file will be fsync-ed every 32 MB of data generated. This is useful 206in order to commit the file to the disk more incrementally and avoid 207big latency spikes. 208# 当redis保存RDB文件时,如果启用以下选项,则每生成32 MB数据将对文件进行fsync处理。这对于将文件更多地提交到磁盘并避免大的延迟峰值很有用。 209rdb-save-incremental-fsync yes 210 211Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good 212idea to start with the default settings and only change them after investigating 213how to improve the performances and how the keys LFU change over time, which 214is possible to inspect via the OBJECT FREQ command. 215# 可以调整Redis LFU逐出(请参阅maxmemory设置)。但是,最好从默认设置开始,仅在研究了如何提高性能以及LFU密钥随时间变化后才进行更改,可以通过OBJECT FREQ命令进行检查。 216There are two tunable parameters in the Redis LFU implementation: the 217counter logarithm factor and the counter decay time. It is important to 218understand what the two parameters mean before changing them. 219# Redis LFU实现中有两个可调参数:计数器对数因子和计数器衰减时间。重要的是在更改它们之前了解两个参数的含义 220The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis 221uses a probabilistic increment with logarithmic behavior. Given the value 222of the old counter, when a key is accessed, the counter is incremented in 223this way: 224# LFU计数器每个密钥只有8位,最大值是255,因此Redis使用具有对数行为的概率增量。给定旧计数器的值,当访问键时,计数器以这种方式递增 2251. A random number R between 0 and 1 is extracted. 2262. A probability P is calculated as 1/(old_value*lfu_log_factor+1). 2273. The counter is incremented only if R < P. 228 229The default lfu-log-factor is 10. This is a table of how the frequency 230counter changes with a different number of accesses with different 231logarithmic factors: 232 233+--------+------------+------------+------------+------------+------------+ 234| factor | 100 hits | 1000 hits | 100K hits | 1M hits | 10M hits | 235+--------+------------+------------+------------+------------+------------+ 236| 0 | 104 | 255 | 255 | 255 | 255 | 237+--------+------------+------------+------------+------------+------------+ 238| 1 | 18 | 49 | 255 | 255 | 255 | 239+--------+------------+------------+------------+------------+------------+ 240| 10 | 10 | 18 | 142 | 255 | 255 | 241+--------+------------+------------+------------+------------+------------+ 242| 100 | 8 | 11 | 49 | 143 | 255 | 243+--------+------------+------------+------------+------------+------------+ 244 245NOTE: The above table was obtained by running the following commands: 246 247redis-benchmark -n 1000000 incr foo 248redis-cli object freq foo 249 250NOTE 2: The counter initial value is 5 in order to give new objects a chance 251to accumulate hits. 252 253The counter decay time is the time, in minutes, that must elapse in order 254for the key counter to be divided by two (or decremented if it has a value 255less <= 10). 256 257The default value for the lfu-decay-time is 1. A special value of 0 means to 258decay the counter every time it happens to be scanned. 259 260lfu-log-factor 10 261lfu-decay-time 1
ACTIVE DEFRAGMENTATION
1ACTIVE DEFRAGMENTATION 2 3What is active defragmentation? 4------------------------------- 5 6Active (online) defragmentation allows a Redis server to compact the 7spaces left between small allocations and deallocations of data in memory, 8thus allowing to reclaim back memory. 9# 通过主动(在线)碎片整理,Redis服务器可以压缩内存中小量分配和释放数据之间剩余的空间,从而允许回收内存 10Fragmentation is a natural process that happens with every allocator (but 11less so with Jemalloc, fortunately) and certain workloads. Normally a server 12restart is needed in order to lower the fragmentation, or at least to flush 13away all the data and create it again. However thanks to this feature 14implemented by Oran Agra for Redis 4.0 this process can happen at runtime 15in a "hot" way, while the server is running. 16# 碎片是每个分配器(幸运的是,Jemalloc发生的情况)和某些工作负载都会发生的自然过程。通常,需要重新启动服务器以减少碎片,或者至少清除所有数据并重新创建。但是,由于Oran Agra为Redis 4.0实现了此功能,因此在服务器运行时,此过程可以在运行时以“热”方式进行 17Basically when the fragmentation is over a certain level (see the 18configuration options below) Redis will start to create new copies of the 19values in contiguous memory regions by exploiting certain specific Jemalloc 20features (in order to understand if an allocation is causing fragmentation 21and to allocate it in a better place), and at the same time, will release the 22old copies of the data. This process, repeated incrementally for all the keys 23will cause the fragmentation to drop back to normal values. 24# 基本上,当碎片超过一定级别时(请参阅下面的配置选项),Redis将开始通过利用某些特定的Jemalloc功能在连续的内存区域中创建值的新副本(以便了解分配是否导致碎片并进行分配更好的位置),同时将释放数据的旧副本。对于所有键,以增量方式重复此过程将导致碎片恢复到正常值 25Important things to understand: 26 271. This feature is disabled by default, and only works if you compiled Redis 28to use the copy of Jemalloc we ship with the source code of Redis. 29This is the default with Linux builds. 30# 默认情况下,此功能是禁用的,并且仅当您编译Redis以使用我们随Redis的源代码提供的Jemalloc副本时才可用。这是Linux构建的默认设置 312. You never need to enable this feature if you don't have fragmentation 32issues. 33# 如果没有碎片问题,则无需启用此功能 343. Once you experience fragmentation, you can enable this feature when 35needed with the command "CONFIG SET activedefrag yes". 36# 遇到碎片之后,可以在需要时使用命令“ CONFIG SET activedefrag yes”启用此功能。 37The configuration parameters are able to fine tune the behavior of the 38defragmentation process. If you are not sure about what they mean it is 39a good idea to leave the defaults untouched. 40# 配置参数能够微调碎片整理过程的行为。如果您不确定它们的含义,最好不要更改默认值 41Enabled active defragmentation 42activedefrag no 43 44Minimum amount of fragmentation waste to start active defrag 45# 启动主动碎片整理的最小碎片废物量 46active-defrag-ignore-bytes 100mb 47 48Minimum percentage of fragmentation to start active defrag 49# 启动主动碎片整理的最小碎片百分比 50active-defrag-threshold-lower 10 51 52Maximum percentage of fragmentation at which we use maximum effort 53# 我们在最大程度地使用碎片的最大百分比 54active-defrag-threshold-upper 100 55 56Minimal effort for defrag in CPU percentage, to be used when the lower 57threshold is reached 58# 达到下限阈值时使用的最小的CPU碎片整理工作 59active-defrag-cycle-min 1 60 61Maximal effort for defrag in CPU percentage, to be used when the upper 62threshold is reached 63# 达到上限时使用的最大的CPU碎片整理工作 64active-defrag-cycle-max 25 65 66Maximum number of set/hash/zset/list fields that will be processed from 67the main dictionary scan 68# 主字典扫描将处理的sethashzsetlist字段的最大数目 69active-defrag-max-scan-fields 1000 70 71Jemalloc background thread for purging will be enabled by default 72# 默认情况下,将启用用于清除的Jemalloc后台线程 73jemalloc-bg-thread yes 74 75It is possible to pin different threads and processes of Redis to specific 76CPUs in your system, in order to maximize the performances of the server. 77This is useful both in order to pin different Redis threads in different 78CPUs, but also in order to make sure that multiple Redis instances running 79in the same host will be pinned to different CPUs. 80# 可以将Redis的不同线程和进程固定到系统中的特定CPU,以最大化服务器的性能。这不仅有助于将不同的Redis线程固定在不同的CPU中,而且还可以确保将在同一主机中运行的多个Redis实例固定到不同的CPU。 81 82Normally you can do this using the "taskset" command, however it is also 83possible to this via Redis configuration directly, both in Linux and FreeBSD. 84# 通常,您可以使用“ taskset”命令来执行此操作,但是在Linux和FreeBSD中,也可以直接通过Redis配置来执行此操作 85You can pin the server/IO threads, bio threads, aof rewrite child process, and 86the bgsave child process. The syntax to specify the cpu list is the same as 87the taskset command: 88# 您可以固定serverIO线程,bio线程,aof重写子进程和bgsave子进程。指定cpu列表的语法与taskset命令相同 89Set redis server/io threads to cpu affinity 0,2,4,6: 90server_cpulist 0-7:2 91 92Set bio threads to cpu affinity 1,3: 93# 将生物线程设置为cpu亲和力1,3 94bio_cpulist 1,3 95 96Set aof rewrite child process to cpu affinity 8,9,10,11: 97# 将aof重写子进程设置为cpu亲和力8,9,10,11 98aof_rewrite_cpulist 8-11 99 100Set bgsave child process to cpu affinity 1,10,11 101# 将bgsave子进程设置为cpu亲和力1,10,11 102bgsave_cpulist 1,10-11
基本上,当碎片超过一定级别时(请参阅下面的配置选项),Redis将开始通过利用某些特定的Jemalloc功能在连续的内存区域中创建值的新副本(以便了解分配是否导致碎片并进行分配更好的位置),同时将释放数据的旧副本。对于所有键,以增量方式重复此过程将导致碎片恢复到正常值,默认情况下,此功能是禁用的,并且仅当您编译Redis以使用我们随Redis的源代码提供的Jemalloc副本时才可用。这是Linux构建的默认设置。如果没有碎片问题,则无需启用此功能
遇到碎片之后,可以在需要时使用命令“ CONFIG SET activedefrag yes”启用此功能。
Activedefrag 配置参数能够微调碎片整理过程的行为,默认为No
active-defrag-ignore-bytes 启动主动碎片整理的最小碎片废物量默认100mb
active-defrag-threshold-lower: 启动主动碎片整理的最小碎片百分比,默认10
active-defrag-cycle-min:达到下限阈值时使用的最小的CPU碎片整理工作,默认1
active-defrag-cycle-max:达到上限时使用的最大的CPU碎片整理工作,默认25
active-defrag-max-scan-fields 主字典扫描将处理的sethashzsetlist字段的最大数目,默认1000
active-defrag-cycle-min:达到下限阈值时使用的最小的CPU碎片整理工作,默认1x