简介

Redis 是一个开源(BSD许可)的内存中的数据结构存储系统,基于C语言开发,它可以用作数据库、缓存和消息中间件。 相比于传统的关系型数据库,Redis的存储方式是key-value型的,说到key-value,我们肯定能想到JSON,但是JSON中value是不区分数据类型的,Redis支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询,能够更好的帮助我们进行数据的存储检索。此外Redis 内置了 复制(replication),LUA脚本(Lua scripting), LRU驱动事件(LRU eviction),事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和自动 分区(Cluster)提供高可用性(high availability)。

Redis可以作为缓存来使用,也可以用作NoSQL数据库,有着丰富的数据类型,不同的数据类型适应的场景也各不相同。

  • String:缓存、计数器、分布式锁等。
  • List:链表、队列、微博关注人时间轴列表等。
  • Hash:用户信息、Hash 表等。
  • Set:去重、赞、踩、共同好友等。
  • Zset:访问量排行榜、点击量排行榜等。

官方网站:https://redis.io

为什么使用

为什么会诞生Redis呢?任何一种技术的产生本身都是为了解决问题。

计算机中数据文件主要存储在磁盘上,磁盘在结构上每一面包含很多磁道,每个磁磁道又按照512字节等分为多个扇区,操作系统在实际读取文件的时候都是以block为单位(扇区的整数倍)进行读取的,随着文件变大,速度会越慢,磁盘IO会成为瓶颈。关系型数据库的出现是为了改善磁盘IO的瓶颈,但整体而言,磁盘IO和数据库的IO总量是相等的,因此出现了了索引的概念,如果没有索引,仅仅只是建了数据库和表,不会有太大帮助,依旧很慢,如MySQL的索引,在读取数据时索引被加载进内存,大大提高了数据定位的速度。而Redis是基于内存进行存储的,磁盘的寻址是ms级别,而内存的寻址级别是ns级别的,因此使用Redis在很大程度上可以解决IO瓶颈,非常适合用户规模体量大的网站以及高并发、高性能低延迟的场景。

关于数据库特性分析:https://db-engines.com/en/ranking
关于Redis性能测试报告:https://redis.com/wp-content/uploads/2021/09/NoSQL-Benchmark.pdf

安装

关于安装就不在赘述,这里简单介绍两种安装方式。

Ubuntu环境安装

使用的Ubuntu环境是20.04LTS桌面版本。由于其软件源已经包含了Redis,因此可以使用apt命令快捷安装。

  1. sudo apt install redis-server

安装完成后会自动启动,查看Redis状态。

  1. starsray@starsray:/opt/docker/redis$ sudo systemctl status redis-server
  2. redis-server.service - Advanced key-value store
  3. Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
  4. Active: active (running) since Sat 2022-03-12 16:01:23 CST; 23s ago
  5. Docs: http://redis.io/documentation,
  6. man:redis-server(1)
  7. Main PID: 10098 (redis-server)
  8. Tasks: 4 (limit: 4915)
  9. Memory: 1.9M
  10. CGroup: /system.slice/redis-server.service
  11. └─10098 /usr/bin/redis-server 127.0.0.1:6379

基本安装就完成了,关于Redis的配置在后面再进行描述。

Docker安装

拉取镜像

使用docker安装Redis首先需要获取Redis的镜像,如果没有指定tag,默认使用的是latest版本。

  1. docker pull redis

也可以搜索Redis镜像,从仓库中选择自己想要使用的镜像。

  1. docker search redis

但是docker search出来的结果是不同镜像的latest版本,如果想使用某个镜像的历史版本,可以使用下面的脚本来查询。

  1. sudo mkdir -p /opt/script
  2. sudo tee /opt/script/docker-search-tag.sh <<-'EOF'
  3. #!/bin/sh
  4. #
  5. # Simple script that will display docker repository tags.
  6. #
  7. # Usage:
  8. # $ docker-show-repo-tags.sh ubuntu centos
  9. for Repo in $* ; do
  10. curl -s -S "https://registry.hub.docker.com/v2/repositories/library/$Repo/tags/" | \
  11. sed -e 's/,/,\n/g' -e 's/\[/\[\n/g' | \
  12. grep '"name"' | \
  13. awk -F\" '{print $4;}' | \
  14. sort -fu | \
  15. sed -e "s/^/${Repo}:/"
  16. done
  17. EOF

授予脚本可执行权限,并且添加软连接到可执行目录

  1. sudo chmod +x docker-search-tag.sh
  2. sudo ln -s /opt/script/docker-search-tag.sh /usr/local/bin/

使用添加的脚本命令搜索Redis镜像tag列表,相关tag都被展示出来了。

  1. starsray@starsray:/usr/bin$ docker-search-tag.sh redis
  2. redis:6.2
  3. redis:6.2.6
  4. redis:6.2.6-bullseye
  5. redis:6.2-bullseye
  6. redis:7.0-rc
  7. redis:7.0-rc2
  8. redis:7.0-rc2-bullseye
  9. redis:7.0-rc-bullseye
  10. redis:bullseye
  11. redis:latest

启动容器

首先获取官网Redis配置,方便随时更改容器中的Redis参数。这里使用docker-compose来配置Redis启动参数。

  1. version: '3'
  2. services:
  3. redis_compose:
  4. restart: always
  5. image: redis:latest
  6. container_name: redis
  7. ports:
  8. - 6379:6379
  9. volumes:
  10. - ./data:/data
  11. - ./logs:/logs
  12. - ./conf/redis.conf:/etc/redis/redis.conf
  13. command:
  14. redis-server /etc/redis/redis.conf --requirepass "yourpassword"

通过volumes分别挂载Redis的配置、数据、日志目录,使用Redis-server指定配置文件的方式来启动服务端。如果不需要设置密码可以不配置requirepass。
启动成功后使用一个可视化工具来链接,推荐一个官方工具Redislnsight。

工具界面,支持命令行CLI,支持主题选择,支持界面化操作等等功能。
image.png

命令行工具

Redis相比于其他缓存技术,有一个明显的优势就是其包含了数据类型,数据类型的好处在于在更新数据时可以精准定位,操作效率高。redis-cli提供了一个非常友好的提示界面,通过help命令可以查看各种命令的使用及简介。

  1. 127.0.0.1:53954> help
  2. redis-cli 5.0.7
  3. To get help about Redis commands type:
  4. "help @<group>" to get a list of commands in <group>
  5. "help <command>" for help on <command>
  6. "help <tab>" to get a list of possible help topics
  7. "quit" to exit
  8. To set redis-cli preferences:
  9. ":set hints" enable online hints
  10. ":set nohints" disable online hints
  11. Set your preferences in ~/.redisclirc

help @表示一个分组的命令集合。例如查看String类型下面包含的命令。

  1. 127.0.0.1:53954> help @string
  2. BITCOUNT key [start end]
  3. summary: Count set bits in a string
  4. since: 2.6.0
  5. BITPOS key bit [start] [end]
  6. summary: Find first bit set or clear in a string
  7. since: 2.8.7
  8. ......

help 用来查看一个具体命令的使用及介绍。

  1. 127.0.0.1:53954> help set
  2. SET key value [expiration EX seconds|PX milliseconds] [NX|XX]
  3. summary: Set the string value of a key
  4. since: 1.0.0
  5. group: string

对象与数据类型

Redis自己封装实现了一些基本的数据类型,从面向对象的角度来说更应该称其为对象类型,这也就是我们常说的String、List、Hash、Set、ZSet等,Redis在实现这些数据类型的时候也是用了诸如SDS、链表、跳跃表等数据结构,了解这些数据结构的实现和特性,对于使用Redis所提供的数据类型会更加的得心应手,接下来这部分会从Redis中用到的数据结构,以及数据结构在不同数据类型中的应用来展示说明。

基本数据结构

SDS

SRedis基于C语言开发,但是并没有直接调用C的字符串,而是通过C语言实现了自身的动态字符串SDS(Simple Dynamic Strings),其内部定义了一个C结构体。

  1. struct sdshdr {
  2. int len;
  3. int free;
  4. char buf[];
  5. };
  • 记录buf中已使用字节数量,等于SDS保存字符串的长度
  • 记录buf中未使用字节的数量
  • 存储字符串的字节数组,Redis是二进制安全的,基于其保存形式

SDS可以说是Redis中最核心的一个实现库了,引用作者的一段原话描述,并且SDS已经作为一个单独的项目被维护。

SDS was a C string I developed in the past for my everyday C programming needs, later it was moved into Redis where it is used extensively and where it was modified in order to be suitable for high performance operations. Now it was extracted from Redis and forked as a stand alone project.

Redis作为一个K-V数据库,包含了几种基本的数据类型,其中K的实现都是以SDS为基础的字符串,其他几种数据类型,如Hash、Set、List这些本身更像是一种数据结构,其内部的元素也都是以SDS为基础的数据形式存储,因此深入理解SDS就很有必要。下面就从几个方面来剖析SDS与C字符串的区别与特性。

  1. 常数复杂度获取字符串的长度

在C中如何表示一个字符串,一般采用N+1的形式来表示,所谓N+1指的是,使用长度为N的数组以及结束字符’\0’来表示一个字符串。因此在获取字符串的长度时候需要通过遍历循环的方式直到遇到字符串’\0’结束确定长度,需要的时间复杂度为O(N)。
未命名文件.svg
由于SDS存储了字符串的长度,因此获取字符串的长度只需要访问属性就能获取,需要的时间复杂度为O(1),在字符串较短的时候这种优势可能不明显,在字符串较长时这种优势就体现出来了。
未命名文件 (1).svg
SDS在设置和更新的时候都会重新计算字符串的长度更新len和free的值,调用者无需关心,也不用手动修改。因此在Redis中无论怎样去获取字符串的长度都不会有性能方面的问题,可以直接获取长度。

  1. 杜绝缓冲区内存溢出

在C语言中字符串的拼接可以使用strcat函数来实现。
语法/原型:

  1. char*strcat(char* strDestination, const char* strSource);

strcat函数把 strSource 所指向的字符串追加到 strDestination 所指向的字符串的结尾,必须要保strDestination 有足够的内存空间来容纳两个字符串,否则会导致溢出错误。
参数说明:

  • strDestination:目的字符串;
  • strSource:源字符串。

注意:strDestination 末尾的\0会被覆盖,strSource 末尾的\0会一起被复制过去,最终的字符串只有一个\0。
返回值:指向 strDestination 的指针。
未命名文件 (3).svg
内存中紧邻着存放着两个字符串S1、S2,如果此时执行strcat函数将S’拼接到S1后面,会导致S1的内存溢出到S2的空间。
SDS同样提供了字符串拼接的sdscat函数,与C中strcat所不同的是SDS字符串在拼接时会有自己的空间分配策略,会先检查现有字符串的空间是否满足需求,如果不满足先进行扩容然后在进行实际的操作,这样就避免了内存溢出的情况。

  1. 减少字符串更新内存重新分配的次数

C字符串中没有记录自身的长度,也没有设置缓冲区,每次对字符串的增长或者缩短都要重新进行内存的分配,尤其是对于高性能、高并发的B/S架构来说,这种频繁的内存分配会是相当大的一部分开支(涉及复杂算法甚至执行系统调用内核状态切换),为了解决这些问题,SDS在内存空间分配的过程中提供了两种优化策略:

  • 空间预分配:用于优化字符串的增长操作,SDS对字符串的预分配空间大小不会超过1M,这个限制由SDS_MAX_PREALLOC来确定,也可以修改。当预分配空间小于1M时,执行的实际分配大小是所需大小的2倍,也就是在分配空间后,sdshdr的len和free属性会相等,如果实际所需空间大于1M,那么程序会多分配1M的未使用空间,也就是free部分空间为1M。
  • 空间惰性释放:这个策略主要针对字符串的缩短操作,Redis作为一个高效的缓存数据库,实际生产中面临着严苛的读写环境,由于字符串总是会频繁的被操作,因此当字符串长度变短后,SDS并不会立即回收这部分空闲的空间,而是使用free进行记录,等待使用或者时机来释放空间。
  1. 二进制安全

所谓二进制安全,是一种主要用于字符串操作函数相关的计算机编程术语。一个二进制安全功能(函数),其本质上将操作输入作为原始的、无任何特殊格式意义的数据流。其在操作上应包含一个字符所能有的256种可能的值(假设为8位字符)。
这也说明了只关心存储不关心格式,但在C字符串中,存储字符必须以某种编码格式进行储存,由于C以’\0’来表示结尾,这种有特殊意义结尾的字符就带来了不安全,如果存储的字符串或二进制流包含空格,数据将会被截断,这中限制使得C字符串不能存储图片、音视频等文件。
如果有一种特殊的使用空格来分割字符串的形式,那么这种结构就不适合用C字符串来保存。如下图所示在读取Hello Redis的时候,在读取完Hello后就不在进行,忽略掉Redis。
未命名文件 (4).svg
SDS所提供的API都是二进制安全的,这也正式buf为字节数组的原因,Redis不是用数组来保存字符,而是来保存一系列二进制位的,因此也可以用来保存图片、音视频等数据,在读取和存储时数据一致,无关乎语言、序列化等因素限制。

  1. 兼容部分C字符串函数

SDS所提供的API都是二进制安全的,并且为了兼容部分C函数,也遵循了末尾为空字符串结尾的习惯,这样就可以使得SDS在保存文本时也可以调用C中string.h库定义的函数,这样也避免了重复区造轮子。

String是Redis中使用最广泛的基本数据类型,一个key所对应的Value最大值为512M,再加上二进制安全,因此可以用来存储图片等其他非结构化的数据。此外对于String,redis还内置了三种编码格式int、embstr和raw,根据其存入值的长短或实际类型而定。

  • int:存储的值必须为整数类型,当数字在0~9999之间时,由于redis在启动时会创建10000个共享对象,所以在存值的时候如果在此数值之间则会将该键的引用指向该共享对象;需要注意的是当通过配置文件参数 maxmemory 设置了 Redis 可用的最大空间大小时,Redis不会使用共享对象,因为对于每一个键值都需要使用一个 redisObject 来记录其LRU信息。
  • embstr:适用于当存入的值小于等于44个字节的字符串。
  • raw:存入的字符串超过44个字节时将转换为raw编码,但当内部编码为embstr的键值对使用append 命令对值进行修改时,无论当前字符串的长度为多少,其内部编码都将转换为raw。

    链表

    链表作为一种常用的数据结构,提供了高效的节点重排能力以及顺序性的节点访问方式,并且可以通过增删节点来调整长度,不同于数组,链表对内存没有严格的要求,可以分布在各个地方,通过指针寻找下一个节点。
    方格取数 (3).svg
    链表在不同的语言中都有实现,例如Java中的LinkedList,但是C语言并没有内置这种结构,因此Redis自己实现了这种结构并应用在各种地方,如列表List、以及发布订阅、慢查询、监视器等功能。
    Redis中链表使用的是双向链表,所谓双向链表,每个节点中包含prev、next两个指针以及值value信息,这种结构更加方便数据的读取。Redis中的链表节点使用listNode结构体来表示。

    1. typedef struct listNode {
    2. struct listNode *prev;
    3. struct listNode *next;
    4. void *value;
    5. } listNode;

    使用listNode就可以组成链表结构,但是Redis又使用list来进行封装,操作链表会更加方便。

    1. typedef struct list
    2. {
    3. listNode *head;
    4. listNode *tail;
    5. void *(*dup)(void *ptr);
    6. void (*free)( void *ptr );
    7. int (*match)( void *ptr, void *key );
    8. unsigned long len;
    9. } list;
  • head 头节点

  • tail 尾节点
  • dup 复制链表节点中保存的值
  • free 释放链表节点中保存的值
  • match 比对链表节点的值和另一个输入值是否相等
  • len 链表长度计数器

如图所示使用list来保存一个包含三个listNode结构的链表:
未命名文件.svg
Redis中的链表特性可以总结为如下几点:

  • listNode
    • 双端:链表节点包含prev、next指针,获取前置节点和后置节点复杂度为O(1),操作快。
    • 无欢:prev、next的指向都是NULL,可以以此为链表终点。
  • list
    • head/tail:list结构包含head和tail,获取链表的头节点和尾节点的复杂度为O(1)。
    • len:存储链表的长度,获取链表长度的复杂度为O(1)。
    • 多态:链表节点使用void*指针保存节点值,并且可以使用dup、free、match三个属性为节点设置类型特定函数,所以链表可以用来保存不同类型的值。

      跳跃表

对象类型

String

List

Hash

Set

Sorted Set

配置详解

Redis配置文件redis.conf指定了很多配置项,对其中常用的配置进行解释,所用到的配置文件与上面官网推荐的一致。

  1. # Redis configuration file example.
  2. # redis的启动需要读取指定路径的配置文件redis.conf
  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. # 当内存需要特殊指定大小时候,redis可以用一种通用的方式来指定内存,例如1k,5GB,或者4M,并且使用这种方式大小写不敏感。
  8. # Note on units: when memory size is needed, it is possible to specify
  9. # it in the usual form of 1k 5GB 4M and so forth:
  10. #
  11. # 1k => 1000 bytes
  12. # 1kb => 1024 bytes
  13. # 1m => 1000000 bytes
  14. # 1mb => 1024*1024 bytes
  15. # 1g => 1000000000 bytes
  16. # 1gb => 1024*1024*1024 bytes
  17. #
  18. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  19. ################################## INCLUDES ###################################
  20. # include可以用来引入一些其他配置文件,类似于spring cloud config引入公共配置的作用,
  21. # 需要注意的是include不会被来自admin或Redis Sentinel的“CONFIG REWRITE”重写,如果有相同
  22. # 的配置项,redis总是会使用最后一次配置的值,如果为了避免配置被覆盖掉最好把include放在配置文
  23. # 件的开始,相反如果需要include来覆盖配置,直接把它放在配置文件的末尾。
  24. #
  25. # Include one or more other config files here. This is useful if you
  26. # have a standard template that goes to all Redis servers but also need
  27. # to customize a few per-server settings. Include files can include
  28. # other files, so use this wisely.
  29. #
  30. # Note that option "include" won't be rewritten by command "CONFIG REWRITE"
  31. # from admin or Redis Sentinel. Since Redis always uses the last processed
  32. # line as value of a configuration directive, you'd better put includes
  33. # at the beginning of this file to avoid overwriting config change at runtime.
  34. #
  35. # If instead you are interested in using includes to override configuration
  36. # options, it is better to use include as the last line.
  37. #
  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. #
  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 available network interfaces on the host machine.
  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. # Each address can be prefixed by "-", which means that redis will not fail to
  52. # start if the address is not available. Being not available only refers to
  53. # addresses that does not correspond to any network interfece. Addresses that
  54. # are already in use will always fail, and unsupported protocols will always BE
  55. # silently skipped.
  56. #
  57. # Examples:
  58. #
  59. # bind 192.168.1.100 10.0.0.1 # listens on two specific IPv4 addresses
  60. # bind 127.0.0.1 ::1 # listens on loopback IPv4 and IPv6
  61. # bind * -::* # like the default, all available interfaces
  62. #
  63. # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
  64. # internet, binding to all the interfaces is dangerous and will expose the
  65. # instance to everybody on the internet. So by default we uncomment the
  66. # following bind directive, that will force Redis to listen only on the
  67. # IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
  68. # will only be able to accept client connections from the same host that it is
  69. # running on).
  70. #
  71. # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
  72. # JUST COMMENT OUT THE FOLLOWING LINE.
  73. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. # bind 127.0.0.1 -::1
  75. # Protected mode is a layer of security protection, in order to avoid that
  76. # Redis instances left open on the internet are accessed and exploited.
  77. #
  78. # When protected mode is on and if:
  79. #
  80. # 1) The server is not binding explicitly to a set of addresses using the
  81. # "bind" directive.
  82. # 2) No password is configured.
  83. #
  84. # The server only accepts connections from clients connecting from the
  85. # IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
  86. # sockets.
  87. #
  88. # By default protected mode is enabled. You should disable it only if
  89. # you are sure you want clients from other hosts to connect to Redis
  90. # even if no authentication is configured, nor a specific set of interfaces
  91. # are explicitly listed using the "bind" directive.
  92. protected-mode no
  93. # Accept connections on the specified port, default is 6379 (IANA #815344).
  94. # If port 0 is specified Redis will not listen on a TCP socket.
  95. port 6379
  96. # TCP listen() backlog.
  97. #
  98. # In high requests-per-second environments you need a high backlog in order
  99. # to avoid slow clients connection issues. Note that the Linux kernel
  100. # will silently truncate it to the value of /proc/sys/net/core/somaxconn so
  101. # make sure to raise both the value of somaxconn and tcp_max_syn_backlog
  102. # in order to get the desired effect.
  103. tcp-backlog 511
  104. # Unix socket.
  105. #
  106. # Specify the path for the Unix socket that will be used to listen for
  107. # incoming connections. There is no default, so Redis will not listen
  108. # on a unix socket when not specified.
  109. #
  110. # unixsocket /run/redis.sock
  111. # unixsocketperm 700
  112. # Close the connection after a client is idle for N seconds (0 to disable)
  113. timeout 0
  114. # TCP keepalive.
  115. #
  116. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
  117. # of communication. This is useful for two reasons:
  118. #
  119. # 1) Detect dead peers.
  120. # 2) Force network equipment in the middle to consider the connection to be
  121. # alive.
  122. #
  123. # On Linux, the specified value (in seconds) is the period used to send ACKs.
  124. # Note that to close the connection the double of the time is needed.
  125. # On other kernels the period depends on the kernel configuration.
  126. #
  127. # A reasonable value for this option is 300 seconds, which is the new
  128. # Redis default starting with Redis 3.2.1.
  129. tcp-keepalive 300
  130. ################################# TLS/SSL #####################################
  131. # By default, TLS/SSL is disabled. To enable it, the "tls-port" configuration
  132. # directive can be used to define TLS-listening ports. To enable TLS on the
  133. # default port, use:
  134. #
  135. # port 0
  136. # tls-port 6379
  137. # Configure a X.509 certificate and private key to use for authenticating the
  138. # server to connected clients, masters or cluster peers. These files should be
  139. # PEM formatted.
  140. #
  141. # tls-cert-file redis.crt
  142. # tls-key-file redis.key
  143. #
  144. # If the key file is encrypted using a passphrase, it can be included here
  145. # as well.
  146. #
  147. # tls-key-file-pass secret
  148. # Normally Redis uses the same certificate for both server functions (accepting
  149. # connections) and client functions (replicating from a master, establishing
  150. # cluster bus connections, etc.).
  151. #
  152. # Sometimes certificates are issued with attributes that designate them as
  153. # client-only or server-only certificates. In that case it may be desired to use
  154. # different certificates for incoming (server) and outgoing (client)
  155. # connections. To do that, use the following directives:
  156. #
  157. # tls-client-cert-file client.crt
  158. # tls-client-key-file client.key
  159. #
  160. # If the key file is encrypted using a passphrase, it can be included here
  161. # as well.
  162. #
  163. # tls-client-key-file-pass secret
  164. # Configure a DH parameters file to enable Diffie-Hellman (DH) key exchange:
  165. #
  166. # tls-dh-params-file redis.dh
  167. # Configure a CA certificate(s) bundle or directory to authenticate TLS/SSL
  168. # clients and peers. Redis requires an explicit configuration of at least one
  169. # of these, and will not implicitly use the system wide configuration.
  170. #
  171. # tls-ca-cert-file ca.crt
  172. # tls-ca-cert-dir /etc/ssl/certs
  173. # By default, clients (including replica servers) on a TLS port are required
  174. # to authenticate using valid client side certificates.
  175. #
  176. # If "no" is specified, client certificates are not required and not accepted.
  177. # If "optional" is specified, client certificates are accepted and must be
  178. # valid if provided, but are not required.
  179. #
  180. # tls-auth-clients no
  181. # tls-auth-clients optional
  182. # By default, a Redis replica does not attempt to establish a TLS connection
  183. # with its master.
  184. #
  185. # Use the following directive to enable TLS on replication links.
  186. #
  187. # tls-replication yes
  188. # By default, the Redis Cluster bus uses a plain TCP connection. To enable
  189. # TLS for the bus protocol, use the following directive:
  190. #
  191. # tls-cluster yes
  192. # By default, only TLSv1.2 and TLSv1.3 are enabled and it is highly recommended
  193. # that older formally deprecated versions are kept disabled to reduce the attack surface.
  194. # You can explicitly specify TLS versions to support.
  195. # Allowed values are case insensitive and include "TLSv1", "TLSv1.1", "TLSv1.2",
  196. # "TLSv1.3" (OpenSSL >= 1.1.1) or any combination.
  197. # To enable only TLSv1.2 and TLSv1.3, use:
  198. #
  199. # tls-protocols "TLSv1.2 TLSv1.3"
  200. # Configure allowed ciphers. See the ciphers(1ssl) manpage for more information
  201. # about the syntax of this string.
  202. #
  203. # Note: this configuration applies only to <= TLSv1.2.
  204. #
  205. # tls-ciphers DEFAULT:!MEDIUM
  206. # Configure allowed TLSv1.3 ciphersuites. See the ciphers(1ssl) manpage for more
  207. # information about the syntax of this string, and specifically for TLSv1.3
  208. # ciphersuites.
  209. #
  210. # tls-ciphersuites TLS_CHACHA20_POLY1305_SHA256
  211. # When choosing a cipher, use the server's preference instead of the client
  212. # preference. By default, the server follows the client's preference.
  213. #
  214. # tls-prefer-server-ciphers yes
  215. # By default, TLS session caching is enabled to allow faster and less expensive
  216. # reconnections by clients that support it. Use the following directive to disable
  217. # caching.
  218. #
  219. # tls-session-caching no
  220. # Change the default number of TLS sessions cached. A zero value sets the cache
  221. # to unlimited size. The default size is 20480.
  222. #
  223. # tls-session-cache-size 5000
  224. # Change the default timeout of cached TLS sessions. The default timeout is 300
  225. # seconds.
  226. #
  227. # tls-session-cache-timeout 60
  228. ################################# GENERAL #####################################
  229. # By default Redis does not run as a daemon. Use 'yes' if you need it.
  230. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
  231. # When Redis is supervised by upstart or systemd, this parameter has no impact.
  232. daemonize no
  233. # If you run Redis from upstart or systemd, Redis can interact with your
  234. # supervision tree. Options:
  235. # supervised no - no supervision interaction
  236. # supervised upstart - signal upstart by putting Redis into SIGSTOP mode
  237. # requires "expect stop" in your upstart job config
  238. # supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
  239. # on startup, and updating Redis status on a regular
  240. # basis.
  241. # supervised auto - detect upstart or systemd method based on
  242. # UPSTART_JOB or NOTIFY_SOCKET environment variables
  243. # Note: these supervision methods only signal "process is ready."
  244. # They do not enable continuous pings back to your supervisor.
  245. #
  246. # The default is "no". To run under upstart/systemd, you can simply uncomment
  247. # the line below:
  248. #
  249. # supervised auto
  250. # If a pid file is specified, Redis writes it where specified at startup
  251. # and removes it at exit.
  252. #
  253. # When the server runs non daemonized, no pid file is created if none is
  254. # specified in the configuration. When the server is daemonized, the pid file
  255. # is used even if not specified, defaulting to "/var/run/redis.pid".
  256. #
  257. # Creating a pid file is best effort: if Redis is not able to create it
  258. # nothing bad happens, the server will start and run normally.
  259. #
  260. # Note that on modern Linux systems "/run/redis.pid" is more conforming
  261. # and should be used instead.
  262. pidfile /var/run/redis_6379.pid
  263. # Specify the server verbosity level.
  264. # This can be one of:
  265. # debug (a lot of information, useful for development/testing)
  266. # verbose (many rarely useful info, but not a mess like the debug level)
  267. # notice (moderately verbose, what you want in production probably)
  268. # warning (only very important / critical messages are logged)
  269. loglevel notice
  270. # Specify the log file name. Also the empty string can be used to force
  271. # Redis to log on the standard output. Note that if you use standard
  272. # output for logging but daemonize, logs will be sent to /dev/null
  273. logfile ""
  274. # To enable logging to the system logger, just set 'syslog-enabled' to yes,
  275. # and optionally update the other syslog parameters to suit your needs.
  276. # syslog-enabled no
  277. # Specify the syslog identity.
  278. # syslog-ident redis
  279. # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.
  280. # syslog-facility local0
  281. # To disable the built in crash log, which will possibly produce cleaner core
  282. # dumps when they are needed, uncomment the following:
  283. #
  284. # crash-log-enabled no
  285. # To disable the fast memory check that's run as part of the crash log, which
  286. # will possibly let redis terminate sooner, uncomment the following:
  287. #
  288. # crash-memcheck-enabled no
  289. # Set the number of databases. The default database is DB 0, you can select
  290. # a different one on a per-connection basis using SELECT <dbid> where
  291. # dbid is a number between 0 and 'databases'-1
  292. databases 16
  293. # By default Redis shows an ASCII art logo only when started to log to the
  294. # standard output and if the standard output is a TTY and syslog logging is
  295. # disabled. Basically this means that normally a logo is displayed only in
  296. # interactive sessions.
  297. #
  298. # However it is possible to force the pre-4.0 behavior and always show a
  299. # ASCII art logo in startup logs by setting the following option to yes.
  300. always-show-logo no
  301. # By default, Redis modifies the process title (as seen in 'top' and 'ps') to
  302. # provide some runtime information. It is possible to disable this and leave
  303. # the process name as executed by setting the following to no.
  304. set-proc-title yes
  305. # When changing the process title, Redis uses the following template to construct
  306. # the modified title.
  307. #
  308. # Template variables are specified in curly brackets. The following variables are
  309. # supported:
  310. #
  311. # {title} Name of process as executed if parent, or type of child process.
  312. # {listen-addr} Bind address or '*' followed by TCP or TLS port listening on, or
  313. # Unix socket if only that's available.
  314. # {server-mode} Special mode, i.e. "[sentinel]" or "[cluster]".
  315. # {port} TCP port listening on, or 0.
  316. # {tls-port} TLS port listening on, or 0.
  317. # {unixsocket} Unix domain socket listening on, or "".
  318. # {config-file} Name of configuration file used.
  319. #
  320. proc-title-template "{title} {listen-addr} {server-mode}"
  321. ################################ SNAPSHOTTING ################################
  322. # Save the DB to disk.
  323. #
  324. # save <seconds> <changes>
  325. #
  326. # Redis will save the DB if both the given number of seconds and the given
  327. # number of write operations against the DB occurred.
  328. #
  329. # Snapshotting can be completely disabled with a single empty string argument
  330. # as in following example:
  331. #
  332. # save ""
  333. #
  334. # Unless specified otherwise, by default Redis will save the DB:
  335. # * After 3600 seconds (an hour) if at least 1 key changed
  336. # * After 300 seconds (5 minutes) if at least 100 keys changed
  337. # * After 60 seconds if at least 10000 keys changed
  338. #
  339. # You can set these explicitly by uncommenting the three following lines.
  340. #
  341. # save 3600 1
  342. # save 300 100
  343. # save 60 10000
  344. # By default Redis will stop accepting writes if RDB snapshots are enabled
  345. # (at least one save point) and the latest background save failed.
  346. # This will make the user aware (in a hard way) that data is not persisting
  347. # on disk properly, otherwise chances are that no one will notice and some
  348. # disaster will happen.
  349. #
  350. # If the background saving process will start working again Redis will
  351. # automatically allow writes again.
  352. #
  353. # However if you have setup your proper monitoring of the Redis server
  354. # and persistence, you may want to disable this feature so that Redis will
  355. # continue to work as usual even if there are problems with disk,
  356. # permissions, and so forth.
  357. stop-writes-on-bgsave-error yes
  358. # Compress string objects using LZF when dump .rdb databases?
  359. # By default compression is enabled as it's almost always a win.
  360. # If you want to save some CPU in the saving child set it to 'no' but
  361. # the dataset will likely be bigger if you have compressible values or keys.
  362. rdbcompression yes
  363. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
  364. # This makes the format more resistant to corruption but there is a performance
  365. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
  366. # for maximum performances.
  367. #
  368. # RDB files created with checksum disabled have a checksum of zero that will
  369. # tell the loading code to skip the check.
  370. rdbchecksum yes
  371. # Enables or disables full sanitation checks for ziplist and listpack etc when
  372. # loading an RDB or RESTORE payload. This reduces the chances of a assertion or
  373. # crash later on while processing commands.
  374. # Options:
  375. # no - Never perform full sanitation
  376. # yes - Always perform full sanitation
  377. # clients - Perform full sanitation only for user connections.
  378. # Excludes: RDB files, RESTORE commands received from the master
  379. # connection, and client connections which have the
  380. # skip-sanitize-payload ACL flag.
  381. # The default should be 'clients' but since it currently affects cluster
  382. # resharding via MIGRATE, it is temporarily set to 'no' by default.
  383. #
  384. # sanitize-dump-payload no
  385. # The filename where to dump the DB
  386. dbfilename dump.rdb
  387. # Remove RDB files used by replication in instances without persistence
  388. # enabled. By default this option is disabled, however there are environments
  389. # where for regulations or other security concerns, RDB files persisted on
  390. # disk by masters in order to feed replicas, or stored on disk by replicas
  391. # in order to load them for the initial synchronization, should be deleted
  392. # ASAP. Note that this option ONLY WORKS in instances that have both AOF
  393. # and RDB persistence disabled, otherwise is completely ignored.
  394. #
  395. # An alternative (and sometimes better) way to obtain the same effect is
  396. # to use diskless replication on both master and replicas instances. However
  397. # in the case of replicas, diskless is not always an option.
  398. rdb-del-sync-files no
  399. # The working directory.
  400. #
  401. # The DB will be written inside this directory, with the filename specified
  402. # above using the 'dbfilename' configuration directive.
  403. #
  404. # The Append Only File will also be created inside this directory.
  405. #
  406. # Note that you must specify a directory here, not a file name.
  407. dir ./
  408. ################################# REPLICATION #################################
  409. # Master-Replica replication. Use replicaof to make a Redis instance a copy of
  410. # another Redis server. A few things to understand ASAP about Redis replication.
  411. #
  412. # +------------------+ +---------------+
  413. # | Master | ---> | Replica |
  414. # | (receive writes) | | (exact copy) |
  415. # +------------------+ +---------------+
  416. #
  417. # 1) Redis replication is asynchronous, but you can configure a master to
  418. # stop accepting writes if it appears to be not connected with at least
  419. # a given number of replicas.
  420. # 2) Redis replicas are able to perform a partial resynchronization with the
  421. # master if the replication link is lost for a relatively small amount of
  422. # time. You may want to configure the replication backlog size (see the next
  423. # sections of this file) with a sensible value depending on your needs.
  424. # 3) Replication is automatic and does not need user intervention. After a
  425. # network partition replicas automatically try to reconnect to masters
  426. # and resynchronize with them.
  427. #
  428. # replicaof <masterip> <masterport>
  429. # If the master is password protected (using the "requirepass" configuration
  430. # directive below) it is possible to tell the replica to authenticate before
  431. # starting the replication synchronization process, otherwise the master will
  432. # refuse the replica request.
  433. #
  434. # masterauth <master-password>
  435. #
  436. # However this is not enough if you are using Redis ACLs (for Redis version
  437. # 6 or greater), and the default user is not capable of running the PSYNC
  438. # command and/or other commands needed for replication. In this case it's
  439. # better to configure a special user to use with replication, and specify the
  440. # masteruser configuration as such:
  441. #
  442. # masteruser <username>
  443. #
  444. # When masteruser is specified, the replica will authenticate against its
  445. # master using the new AUTH form: AUTH <username> <password>.
  446. # When a replica loses its connection with the master, or when the replication
  447. # is still in progress, the replica can act in two different ways:
  448. #
  449. # 1) if replica-serve-stale-data is set to 'yes' (the default) the replica will
  450. # still reply to client requests, possibly with out of date data, or the
  451. # data set may just be empty if this is the first synchronization.
  452. #
  453. # 2) If replica-serve-stale-data is set to 'no' the replica will reply with
  454. # an error "SYNC with master in progress" to all commands except:
  455. # INFO, REPLICAOF, AUTH, PING, SHUTDOWN, REPLCONF, ROLE, CONFIG, SUBSCRIBE,
  456. # UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, PUBLISH, PUBSUB, COMMAND, POST,
  457. # HOST and LATENCY.
  458. #
  459. replica-serve-stale-data yes
  460. # You can configure a replica instance to accept writes or not. Writing against
  461. # a replica instance may be useful to store some ephemeral data (because data
  462. # written on a replica will be easily deleted after resync with the master) but
  463. # may also cause problems if clients are writing to it because of a
  464. # misconfiguration.
  465. #
  466. # Since Redis 2.6 by default replicas are read-only.
  467. #
  468. # Note: read only replicas are not designed to be exposed to untrusted clients
  469. # on the internet. It's just a protection layer against misuse of the instance.
  470. # Still a read only replica exports by default all the administrative commands
  471. # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
  472. # security of read only replicas using 'rename-command' to shadow all the
  473. # administrative / dangerous commands.
  474. replica-read-only yes
  475. # Replication SYNC strategy: disk or socket.
  476. #
  477. # New replicas and reconnecting replicas that are not able to continue the
  478. # replication process just receiving differences, need to do what is called a
  479. # "full synchronization". An RDB file is transmitted from the master to the
  480. # replicas.
  481. #
  482. # The transmission can happen in two different ways:
  483. #
  484. # 1) Disk-backed: The Redis master creates a new process that writes the RDB
  485. # file on disk. Later the file is transferred by the parent
  486. # process to the replicas incrementally.
  487. # 2) Diskless: The Redis master creates a new process that directly writes the
  488. # RDB file to replica sockets, without touching the disk at all.
  489. #
  490. # With disk-backed replication, while the RDB file is generated, more replicas
  491. # can be queued and served with the RDB file as soon as the current child
  492. # producing the RDB file finishes its work. With diskless replication instead
  493. # once the transfer starts, new replicas arriving will be queued and a new
  494. # transfer will start when the current one terminates.
  495. #
  496. # When diskless replication is used, the master waits a configurable amount of
  497. # time (in seconds) before starting the transfer in the hope that multiple
  498. # replicas will arrive and the transfer can be parallelized.
  499. #
  500. # With slow disks and fast (large bandwidth) networks, diskless replication
  501. # works better.
  502. repl-diskless-sync no
  503. # When diskless replication is enabled, it is possible to configure the delay
  504. # the server waits in order to spawn the child that transfers the RDB via socket
  505. # to the replicas.
  506. #
  507. # This is important since once the transfer starts, it is not possible to serve
  508. # new replicas arriving, that will be queued for the next RDB transfer, so the
  509. # server waits a delay in order to let more replicas arrive.
  510. #
  511. # The delay is specified in seconds, and by default is 5 seconds. To disable
  512. # it entirely just set it to 0 seconds and the transfer will start ASAP.
  513. repl-diskless-sync-delay 5
  514. # -----------------------------------------------------------------------------
  515. # WARNING: RDB diskless load is experimental. Since in this setup the replica
  516. # does not immediately store an RDB on disk, it may cause data loss during
  517. # failovers. RDB diskless load + Redis modules not handling I/O reads may also
  518. # cause Redis to abort in case of I/O errors during the initial synchronization
  519. # stage with the master. Use only if you know what you are doing.
  520. # -----------------------------------------------------------------------------
  521. #
  522. # Replica can load the RDB it reads from the replication link directly from the
  523. # socket, or store the RDB to a file and read that file after it was completely
  524. # received from the master.
  525. #
  526. # In many cases the disk is slower than the network, and storing and loading
  527. # the RDB file may increase replication time (and even increase the master's
  528. # Copy on Write memory and salve buffers).
  529. # However, parsing the RDB file directly from the socket may mean that we have
  530. # to flush the contents of the current database before the full rdb was
  531. # received. For this reason we have the following options:
  532. #
  533. # "disabled" - Don't use diskless load (store the rdb file to the disk first)
  534. # "on-empty-db" - Use diskless load only when it is completely safe.
  535. # "swapdb" - Keep a copy of the current db contents in RAM while parsing
  536. # the data directly from the socket. note that this requires
  537. # sufficient memory, if you don't have it, you risk an OOM kill.
  538. repl-diskless-load disabled
  539. # Replicas send PINGs to server in a predefined interval. It's possible to
  540. # change this interval with the repl_ping_replica_period option. The default
  541. # value is 10 seconds.
  542. #
  543. # repl-ping-replica-period 10
  544. # The following option sets the replication timeout for:
  545. #
  546. # 1) Bulk transfer I/O during SYNC, from the point of view of replica.
  547. # 2) Master timeout from the point of view of replicas (data, pings).
  548. # 3) Replica timeout from the point of view of masters (REPLCONF ACK pings).
  549. #
  550. # It is important to make sure that this value is greater than the value
  551. # specified for repl-ping-replica-period otherwise a timeout will be detected
  552. # every time there is low traffic between the master and the replica. The default
  553. # value is 60 seconds.
  554. #
  555. # repl-timeout 60
  556. # Disable TCP_NODELAY on the replica socket after SYNC?
  557. #
  558. # If you select "yes" Redis will use a smaller number of TCP packets and
  559. # less bandwidth to send data to replicas. But this can add a delay for
  560. # the data to appear on the replica side, up to 40 milliseconds with
  561. # Linux kernels using a default configuration.
  562. #
  563. # If you select "no" the delay for data to appear on the replica side will
  564. # be reduced but more bandwidth will be used for replication.
  565. #
  566. # By default we optimize for low latency, but in very high traffic conditions
  567. # or when the master and replicas are many hops away, turning this to "yes" may
  568. # be a good idea.
  569. repl-disable-tcp-nodelay no
  570. # Set the replication backlog size. The backlog is a buffer that accumulates
  571. # replica data when replicas are disconnected for some time, so that when a
  572. # replica wants to reconnect again, often a full resync is not needed, but a
  573. # partial resync is enough, just passing the portion of data the replica
  574. # missed while disconnected.
  575. #
  576. # The bigger the replication backlog, the longer the replica can endure the
  577. # disconnect and later be able to perform a partial resynchronization.
  578. #
  579. # The backlog is only allocated if there is at least one replica connected.
  580. #
  581. # repl-backlog-size 1mb
  582. # After a master has no connected replicas for some time, the backlog will be
  583. # freed. The following option configures the amount of seconds that need to
  584. # elapse, starting from the time the last replica disconnected, for the backlog
  585. # buffer to be freed.
  586. #
  587. # Note that replicas never free the backlog for timeout, since they may be
  588. # promoted to masters later, and should be able to correctly "partially
  589. # resynchronize" with other replicas: hence they should always accumulate backlog.
  590. #
  591. # A value of 0 means to never release the backlog.
  592. #
  593. # repl-backlog-ttl 3600
  594. # The replica priority is an integer number published by Redis in the INFO
  595. # output. It is used by Redis Sentinel in order to select a replica to promote
  596. # into a master if the master is no longer working correctly.
  597. #
  598. # A replica with a low priority number is considered better for promotion, so
  599. # for instance if there are three replicas with priority 10, 100, 25 Sentinel
  600. # will pick the one with priority 10, that is the lowest.
  601. #
  602. # However a special priority of 0 marks the replica as not able to perform the
  603. # role of master, so a replica with priority of 0 will never be selected by
  604. # Redis Sentinel for promotion.
  605. #
  606. # By default the priority is 100.
  607. replica-priority 100
  608. # -----------------------------------------------------------------------------
  609. # By default, Redis Sentinel includes all replicas in its reports. A replica
  610. # can be excluded from Redis Sentinel's announcements. An unannounced replica
  611. # will be ignored by the 'sentinel replicas <master>' command and won't be
  612. # exposed to Redis Sentinel's clients.
  613. #
  614. # This option does not change the behavior of replica-priority. Even with
  615. # replica-announced set to 'no', the replica can be promoted to master. To
  616. # prevent this behavior, set replica-priority to 0.
  617. #
  618. # replica-announced yes
  619. # It is possible for a master to stop accepting writes if there are less than
  620. # N replicas connected, having a lag less or equal than M seconds.
  621. #
  622. # The N replicas need to be in "online" state.
  623. #
  624. # The lag in seconds, that must be <= the specified value, is calculated from
  625. # the last ping received from the replica, that is usually sent every second.
  626. #
  627. # This option does not GUARANTEE that N replicas will accept the write, but
  628. # will limit the window of exposure for lost writes in case not enough replicas
  629. # are available, to the specified number of seconds.
  630. #
  631. # For example to require at least 3 replicas with a lag <= 10 seconds use:
  632. #
  633. # min-replicas-to-write 3
  634. # min-replicas-max-lag 10
  635. #
  636. # Setting one or the other to 0 disables the feature.
  637. #
  638. # By default min-replicas-to-write is set to 0 (feature disabled) and
  639. # min-replicas-max-lag is set to 10.
  640. # A Redis master is able to list the address and port of the attached
  641. # replicas in different ways. For example the "INFO replication" section
  642. # offers this information, which is used, among other tools, by
  643. # Redis Sentinel in order to discover replica instances.
  644. # Another place where this info is available is in the output of the
  645. # "ROLE" command of a master.
  646. #
  647. # The listed IP address and port normally reported by a replica is
  648. # obtained in the following way:
  649. #
  650. # IP: The address is auto detected by checking the peer address
  651. # of the socket used by the replica to connect with the master.
  652. #
  653. # Port: The port is communicated by the replica during the replication
  654. # handshake, and is normally the port that the replica is using to
  655. # listen for connections.
  656. #
  657. # However when port forwarding or Network Address Translation (NAT) is
  658. # used, the replica may actually be reachable via different IP and port
  659. # pairs. The following two options can be used by a replica in order to
  660. # report to its master a specific set of IP and port, so that both INFO
  661. # and ROLE will report those values.
  662. #
  663. # There is no need to use both the options if you need to override just
  664. # the port or the IP address.
  665. #
  666. # replica-announce-ip 5.5.5.5
  667. # replica-announce-port 1234
  668. ############################### KEYS TRACKING #################################
  669. # Redis implements server assisted support for client side caching of values.
  670. # This is implemented using an invalidation table that remembers, using
  671. # a radix key indexed by key name, what clients have which keys. In turn
  672. # this is used in order to send invalidation messages to clients. Please
  673. # check this page to understand more about the feature:
  674. #
  675. # https://redis.io/topics/client-side-caching
  676. #
  677. # When tracking is enabled for a client, all the read only queries are assumed
  678. # to be cached: this will force Redis to store information in the invalidation
  679. # table. When keys are modified, such information is flushed away, and
  680. # invalidation messages are sent to the clients. However if the workload is
  681. # heavily dominated by reads, Redis could use more and more memory in order
  682. # to track the keys fetched by many clients.
  683. #
  684. # For this reason it is possible to configure a maximum fill value for the
  685. # invalidation table. By default it is set to 1M of keys, and once this limit
  686. # is reached, Redis will start to evict keys in the invalidation table
  687. # even if they were not modified, just to reclaim memory: this will in turn
  688. # force the clients to invalidate the cached values. Basically the table
  689. # maximum size is a trade off between the memory you want to spend server
  690. # side to track information about who cached what, and the ability of clients
  691. # to retain cached objects in memory.
  692. #
  693. # If you set the value to 0, it means there are no limits, and Redis will
  694. # retain as many keys as needed in the invalidation table.
  695. # In the "stats" INFO section, you can find information about the number of
  696. # keys in the invalidation table at every given moment.
  697. #
  698. # Note: when key tracking is used in broadcasting mode, no memory is used
  699. # in the server side so this setting is useless.
  700. #
  701. # tracking-table-max-keys 1000000
  702. ################################## SECURITY ###################################
  703. # Warning: since Redis is pretty fast, an outside user can try up to
  704. # 1 million passwords per second against a modern box. This means that you
  705. # should use very strong passwords, otherwise they will be very easy to break.
  706. # Note that because the password is really a shared secret between the client
  707. # and the server, and should not be memorized by any human, the password
  708. # can be easily a long string from /dev/urandom or whatever, so by using a
  709. # long and unguessable password no brute force attack will be possible.
  710. # Redis ACL users are defined in the following format:
  711. #
  712. # user <username> ... acl rules ...
  713. #
  714. # For example:
  715. #
  716. # user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
  717. #
  718. # The special username "default" is used for new connections. If this user
  719. # has the "nopass" rule, then new connections will be immediately authenticated
  720. # as the "default" user without the need of any password provided via the
  721. # AUTH command. Otherwise if the "default" user is not flagged with "nopass"
  722. # the connections will start in not authenticated state, and will require
  723. # AUTH (or the HELLO command AUTH option) in order to be authenticated and
  724. # start to work.
  725. #
  726. # The ACL rules that describe what a user can do are the following:
  727. #
  728. # on Enable the user: it is possible to authenticate as this user.
  729. # off Disable the user: it's no longer possible to authenticate
  730. # with this user, however the already authenticated connections
  731. # will still work.
  732. # skip-sanitize-payload RESTORE dump-payload sanitation is skipped.
  733. # sanitize-payload RESTORE dump-payload is sanitized (default).
  734. # +<command> Allow the execution of that command
  735. # -<command> Disallow the execution of that command
  736. # +@<category> Allow the execution of all the commands in such category
  737. # with valid categories are like @admin, @set, @sortedset, ...
  738. # and so forth, see the full list in the server.c file where
  739. # the Redis command table is described and defined.
  740. # The special category @all means all the commands, but currently
  741. # present in the server, and that will be loaded in the future
  742. # via modules.
  743. # +<command>|subcommand Allow a specific subcommand of an otherwise
  744. # disabled command. Note that this form is not
  745. # allowed as negative like -DEBUG|SEGFAULT, but
  746. # only additive starting with "+".
  747. # allcommands Alias for +@all. Note that it implies the ability to execute
  748. # all the future commands loaded via the modules system.
  749. # nocommands Alias for -@all.
  750. # ~<pattern> Add a pattern of keys that can be mentioned as part of
  751. # commands. For instance ~* allows all the keys. The pattern
  752. # is a glob-style pattern like the one of KEYS.
  753. # It is possible to specify multiple patterns.
  754. # allkeys Alias for ~*
  755. # resetkeys Flush the list of allowed keys patterns.
  756. # &<pattern> Add a glob-style pattern of Pub/Sub channels that can be
  757. # accessed by the user. It is possible to specify multiple channel
  758. # patterns.
  759. # allchannels Alias for &*
  760. # resetchannels Flush the list of allowed channel patterns.
  761. # ><password> Add this password to the list of valid password for the user.
  762. # For example >mypass will add "mypass" to the list.
  763. # This directive clears the "nopass" flag (see later).
  764. # <<password> Remove this password from the list of valid passwords.
  765. # nopass All the set passwords of the user are removed, and the user
  766. # is flagged as requiring no password: it means that every
  767. # password will work against this user. If this directive is
  768. # used for the default user, every new connection will be
  769. # immediately authenticated with the default user without
  770. # any explicit AUTH command required. Note that the "resetpass"
  771. # directive will clear this condition.
  772. # resetpass Flush the list of allowed passwords. Moreover removes the
  773. # "nopass" status. After "resetpass" the user has no associated
  774. # passwords and there is no way to authenticate without adding
  775. # some password (or setting it as "nopass" later).
  776. # reset Performs the following actions: resetpass, resetkeys, off,
  777. # -@all. The user returns to the same state it has immediately
  778. # after its creation.
  779. #
  780. # ACL rules can be specified in any order: for instance you can start with
  781. # passwords, then flags, or key patterns. However note that the additive
  782. # and subtractive rules will CHANGE MEANING depending on the ordering.
  783. # For instance see the following example:
  784. #
  785. # user alice on +@all -DEBUG ~* >somepassword
  786. #
  787. # This will allow "alice" to use all the commands with the exception of the
  788. # DEBUG command, since +@all added all the commands to the set of the commands
  789. # alice can use, and later DEBUG was removed. However if we invert the order
  790. # of two ACL rules the result will be different:
  791. #
  792. # user alice on -DEBUG +@all ~* >somepassword
  793. #
  794. # Now DEBUG was removed when alice had yet no commands in the set of allowed
  795. # commands, later all the commands are added, so the user will be able to
  796. # execute everything.
  797. #
  798. # Basically ACL rules are processed left-to-right.
  799. #
  800. # For more information about ACL configuration please refer to
  801. # the Redis web site at https://redis.io/topics/acl
  802. # ACL LOG
  803. #
  804. # The ACL Log tracks failed commands and authentication events associated
  805. # with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
  806. # by ACLs. The ACL Log is stored in memory. You can reclaim memory with
  807. # ACL LOG RESET. Define the maximum entry length of the ACL Log below.
  808. acllog-max-len 128
  809. # Using an external ACL file
  810. #
  811. # Instead of configuring users here in this file, it is possible to use
  812. # a stand-alone file just listing users. The two methods cannot be mixed:
  813. # if you configure users here and at the same time you activate the external
  814. # ACL file, the server will refuse to start.
  815. #
  816. # The format of the external ACL user file is exactly the same as the
  817. # format that is used inside redis.conf to describe users.
  818. #
  819. # aclfile /etc/redis/users.acl
  820. # IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
  821. # layer on top of the new ACL system. The option effect will be just setting
  822. # the password for the default user. Clients will still authenticate using
  823. # AUTH <password> as usually, or more explicitly with AUTH default <password>
  824. # if they follow the new protocol: both will work.
  825. #
  826. # The requirepass is not compatable with aclfile option and the ACL LOAD
  827. # command, these will cause requirepass to be ignored.
  828. #
  829. # requirepass foobared
  830. # New users are initialized with restrictive permissions by default, via the
  831. # equivalent of this ACL rule 'off resetkeys -@all'. Starting with Redis 6.2, it
  832. # is possible to manage access to Pub/Sub channels with ACL rules as well. The
  833. # default Pub/Sub channels permission if new users is controlled by the
  834. # acl-pubsub-default configuration directive, which accepts one of these values:
  835. #
  836. # allchannels: grants access to all Pub/Sub channels
  837. # resetchannels: revokes access to all Pub/Sub channels
  838. #
  839. # To ensure backward compatibility while upgrading Redis 6.0, acl-pubsub-default
  840. # defaults to the 'allchannels' permission.
  841. #
  842. # Future compatibility note: it is very likely that in a future version of Redis
  843. # the directive's default of 'allchannels' will be changed to 'resetchannels' in
  844. # order to provide better out-of-the-box Pub/Sub security. Therefore, it is
  845. # recommended that you explicitly define Pub/Sub permissions for all users
  846. # rather then rely on implicit default values. Once you've set explicit
  847. # Pub/Sub for all existing users, you should uncomment the following line.
  848. #
  849. # acl-pubsub-default resetchannels
  850. # Command renaming (DEPRECATED).
  851. #
  852. # ------------------------------------------------------------------------
  853. # WARNING: avoid using this option if possible. Instead use ACLs to remove
  854. # commands from the default user, and put them only in some admin user you
  855. # create for administrative purposes.
  856. # ------------------------------------------------------------------------
  857. #
  858. # It is possible to change the name of dangerous commands in a shared
  859. # environment. For instance the CONFIG command may be renamed into something
  860. # hard to guess so that it will still be available for internal-use tools
  861. # but not available for general clients.
  862. #
  863. # Example:
  864. #
  865. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  866. #
  867. # It is also possible to completely kill a command by renaming it into
  868. # an empty string:
  869. #
  870. # rename-command CONFIG ""
  871. #
  872. # Please note that changing the name of commands that are logged into the
  873. # AOF file or transmitted to replicas may cause problems.
  874. ################################### CLIENTS ####################################
  875. # Set the max number of connected clients at the same time. By default
  876. # this limit is set to 10000 clients, however if the Redis server is not
  877. # able to configure the process file limit to allow for the specified limit
  878. # the max number of allowed clients is set to the current file limit
  879. # minus 32 (as Redis reserves a few file descriptors for internal uses).
  880. #
  881. # Once the limit is reached Redis will close all the new connections sending
  882. # an error 'max number of clients reached'.
  883. #
  884. # IMPORTANT: When Redis Cluster is used, the max number of connections is also
  885. # shared with the cluster bus: every node in the cluster will use two
  886. # connections, one incoming and another outgoing. It is important to size the
  887. # limit accordingly in case of very large clusters.
  888. #
  889. # maxclients 10000
  890. ############################## MEMORY MANAGEMENT ################################
  891. # Set a memory usage limit to the specified amount of bytes.
  892. # When the memory limit is reached Redis will try to remove keys
  893. # according to the eviction policy selected (see maxmemory-policy).
  894. #
  895. # If Redis can't remove keys according to the policy, or if the policy is
  896. # set to 'noeviction', Redis will start to reply with errors to commands
  897. # that would use more memory, like SET, LPUSH, and so on, and will continue
  898. # to reply to read-only commands like GET.
  899. #
  900. # This option is usually useful when using Redis as an LRU or LFU cache, or to
  901. # set a hard memory limit for an instance (using the 'noeviction' policy).
  902. #
  903. # WARNING: If you have replicas attached to an instance with maxmemory on,
  904. # the size of the output buffers needed to feed the replicas are subtracted
  905. # from the used memory count, so that network problems / resyncs will
  906. # not trigger a loop where keys are evicted, and in turn the output
  907. # buffer of replicas is full with DELs of keys evicted triggering the deletion
  908. # of more keys, and so forth until the database is completely emptied.
  909. #
  910. # In short... if you have replicas attached it is suggested that you set a lower
  911. # limit for maxmemory so that there is some free RAM on the system for replica
  912. # output buffers (but this is not needed if the policy is 'noeviction').
  913. #
  914. # maxmemory <bytes>
  915. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  916. # is reached. You can select one from the following behaviors:
  917. #
  918. # volatile-lru -> Evict using approximated LRU, only keys with an expire set.
  919. # allkeys-lru -> Evict any key using approximated LRU.
  920. # volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
  921. # allkeys-lfu -> Evict any key using approximated LFU.
  922. # volatile-random -> Remove a random key having an expire set.
  923. # allkeys-random -> Remove a random key, any key.
  924. # volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
  925. # noeviction -> Don't evict anything, just return an error on write operations.
  926. #
  927. # LRU means Least Recently Used
  928. # LFU means Least Frequently Used
  929. #
  930. # Both LRU, LFU and volatile-ttl are implemented using approximated
  931. # randomized algorithms.
  932. #
  933. # Note: with any of the above policies, when there are no suitable keys for
  934. # eviction, Redis will return an error on write operations that require
  935. # more memory. These are usually commands that create new keys, add data or
  936. # modify existing keys. A few examples are: SET, INCR, HSET, LPUSH, SUNIONSTORE,
  937. # SORT (due to the STORE argument), and EXEC (if the transaction includes any
  938. # command that requires memory).
  939. #
  940. # The default is:
  941. #
  942. # maxmemory-policy noeviction
  943. # LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
  944. # algorithms (in order to save memory), so you can tune it for speed or
  945. # accuracy. By default Redis will check five keys and pick the one that was
  946. # used least recently, you can change the sample size using the following
  947. # configuration directive.
  948. #
  949. # The default of 5 produces good enough results. 10 Approximates very closely
  950. # true LRU but costs more CPU. 3 is faster but not very accurate.
  951. #
  952. # maxmemory-samples 5
  953. # Eviction processing is designed to function well with the default setting.
  954. # If there is an unusually large amount of write traffic, this value may need to
  955. # be increased. Decreasing this value may reduce latency at the risk of
  956. # eviction processing effectiveness
  957. # 0 = minimum latency, 10 = default, 100 = process without regard to latency
  958. #
  959. # maxmemory-eviction-tenacity 10
  960. # Starting from Redis 5, by default a replica will ignore its maxmemory setting
  961. # (unless it is promoted to master after a failover or manually). It means
  962. # that the eviction of keys will be just handled by the master, sending the
  963. # DEL commands to the replica as keys evict in the master side.
  964. #
  965. # This behavior ensures that masters and replicas stay consistent, and is usually
  966. # what you want, however if your replica is writable, or you want the replica
  967. # to have a different memory setting, and you are sure all the writes performed
  968. # to the replica are idempotent, then you may change this default (but be sure
  969. # to understand what you are doing).
  970. #
  971. # Note that since the replica by default does not evict, it may end using more
  972. # memory than the one set via maxmemory (there are certain buffers that may
  973. # be larger on the replica, or data structures may sometimes take more memory
  974. # and so forth). So make sure you monitor your replicas and make sure they
  975. # have enough memory to never hit a real out-of-memory condition before the
  976. # master hits the configured maxmemory setting.
  977. #
  978. # replica-ignore-maxmemory yes
  979. # Redis reclaims expired keys in two ways: upon access when those keys are
  980. # found to be expired, and also in background, in what is called the
  981. # "active expire key". The key space is slowly and interactively scanned
  982. # looking for expired keys to reclaim, so that it is possible to free memory
  983. # of keys that are expired and will never be accessed again in a short time.
  984. #
  985. # The default effort of the expire cycle will try to avoid having more than
  986. # ten percent of expired keys still in memory, and will try to avoid consuming
  987. # more than 25% of total memory and to add latency to the system. However
  988. # it is possible to increase the expire "effort" that is normally set to
  989. # "1", to a greater value, up to the value "10". At its maximum value the
  990. # system will use more CPU, longer cycles (and technically may introduce
  991. # more latency), and will tolerate less already expired keys still present
  992. # in the system. It's a tradeoff between memory, CPU and latency.
  993. #
  994. # active-expire-effort 1
  995. ############################# LAZY FREEING ####################################
  996. # Redis has two primitives to delete keys. One is called DEL and is a blocking
  997. # deletion of the object. It means that the server stops processing new commands
  998. # in order to reclaim all the memory associated with an object in a synchronous
  999. # way. If the key deleted is associated with a small object, the time needed
  1000. # in order to execute the DEL command is very small and comparable to most other
  1001. # O(1) or O(log_N) commands in Redis. However if the key is associated with an
  1002. # aggregated value containing millions of elements, the server can block for
  1003. # a long time (even seconds) in order to complete the operation.
  1004. #
  1005. # For the above reasons Redis also offers non blocking deletion primitives
  1006. # such as UNLINK (non blocking DEL) and the ASYNC option of FLUSHALL and
  1007. # FLUSHDB commands, in order to reclaim memory in background. Those commands
  1008. # are executed in constant time. Another thread will incrementally free the
  1009. # object in the background as fast as possible.
  1010. #
  1011. # DEL, UNLINK and ASYNC option of FLUSHALL and FLUSHDB are user-controlled.
  1012. # It's up to the design of the application to understand when it is a good
  1013. # idea to use one or the other. However the Redis server sometimes has to
  1014. # delete keys or flush the whole database as a side effect of other operations.
  1015. # Specifically Redis deletes objects independently of a user call in the
  1016. # following scenarios:
  1017. #
  1018. # 1) On eviction, because of the maxmemory and maxmemory policy configurations,
  1019. # in order to make room for new data, without going over the specified
  1020. # memory limit.
  1021. # 2) Because of expire: when a key with an associated time to live (see the
  1022. # EXPIRE command) must be deleted from memory.
  1023. # 3) Because of a side effect of a command that stores data on a key that may
  1024. # already exist. For example the RENAME command may delete the old key
  1025. # content when it is replaced with another one. Similarly SUNIONSTORE
  1026. # or SORT with STORE option may delete existing keys. The SET command
  1027. # itself removes any old content of the specified key in order to replace
  1028. # it with the specified string.
  1029. # 4) During replication, when a replica performs a full resynchronization with
  1030. # its master, the content of the whole database is removed in order to
  1031. # load the RDB file just transferred.
  1032. #
  1033. # In all the above cases the default is to delete objects in a blocking way,
  1034. # like if DEL was called. However you can configure each case specifically
  1035. # in order to instead release memory in a non-blocking way like if UNLINK
  1036. # was called, using the following configuration directives.
  1037. lazyfree-lazy-eviction no
  1038. lazyfree-lazy-expire no
  1039. lazyfree-lazy-server-del no
  1040. replica-lazy-flush no
  1041. # It is also possible, for the case when to replace the user code DEL calls
  1042. # with UNLINK calls is not easy, to modify the default behavior of the DEL
  1043. # command to act exactly like UNLINK, using the following configuration
  1044. # directive:
  1045. lazyfree-lazy-user-del no
  1046. # FLUSHDB, FLUSHALL, and SCRIPT FLUSH support both asynchronous and synchronous
  1047. # deletion, which can be controlled by passing the [SYNC|ASYNC] flags into the
  1048. # commands. When neither flag is passed, this directive will be used to determine
  1049. # if the data should be deleted asynchronously.
  1050. lazyfree-lazy-user-flush no
  1051. ################################ THREADED I/O #################################
  1052. # Redis is mostly single threaded, however there are certain threaded
  1053. # operations such as UNLINK, slow I/O accesses and other things that are
  1054. # performed on side threads.
  1055. #
  1056. # Now it is also possible to handle Redis clients socket reads and writes
  1057. # in different I/O threads. Since especially writing is so slow, normally
  1058. # Redis users use pipelining in order to speed up the Redis performances per
  1059. # core, and spawn multiple instances in order to scale more. Using I/O
  1060. # threads it is possible to easily speedup two times Redis without resorting
  1061. # to pipelining nor sharding of the instance.
  1062. #
  1063. # By default threading is disabled, we suggest enabling it only in machines
  1064. # that have at least 4 or more cores, leaving at least one spare core.
  1065. # Using more than 8 threads is unlikely to help much. We also recommend using
  1066. # threaded I/O only if you actually have performance problems, with Redis
  1067. # instances being able to use a quite big percentage of CPU time, otherwise
  1068. # there is no point in using this feature.
  1069. #
  1070. # So for instance if you have a four cores boxes, try to use 2 or 3 I/O
  1071. # threads, if you have a 8 cores, try to use 6 threads. In order to
  1072. # enable I/O threads use the following configuration directive:
  1073. #
  1074. # io-threads 4
  1075. #
  1076. # Setting io-threads to 1 will just use the main thread as usual.
  1077. # When I/O threads are enabled, we only use threads for writes, that is
  1078. # to thread the write(2) syscall and transfer the client buffers to the
  1079. # socket. However it is also possible to enable threading of reads and
  1080. # protocol parsing using the following configuration directive, by setting
  1081. # it to yes:
  1082. #
  1083. # io-threads-do-reads no
  1084. #
  1085. # Usually threading reads doesn't help much.
  1086. #
  1087. # NOTE 1: This configuration directive cannot be changed at runtime via
  1088. # CONFIG SET. Aso this feature currently does not work when SSL is
  1089. # enabled.
  1090. #
  1091. # NOTE 2: If you want to test the Redis speedup using redis-benchmark, make
  1092. # sure you also run the benchmark itself in threaded mode, using the
  1093. # --threads option to match the number of Redis threads, otherwise you'll not
  1094. # be able to notice the improvements.
  1095. ############################ KERNEL OOM CONTROL ##############################
  1096. # On Linux, it is possible to hint the kernel OOM killer on what processes
  1097. # should be killed first when out of memory.
  1098. #
  1099. # Enabling this feature makes Redis actively control the oom_score_adj value
  1100. # for all its processes, depending on their role. The default scores will
  1101. # attempt to have background child processes killed before all others, and
  1102. # replicas killed before masters.
  1103. #
  1104. # Redis supports three options:
  1105. #
  1106. # no: Don't make changes to oom-score-adj (default).
  1107. # yes: Alias to "relative" see below.
  1108. # absolute: Values in oom-score-adj-values are written as is to the kernel.
  1109. # relative: Values are used relative to the initial value of oom_score_adj when
  1110. # the server starts and are then clamped to a range of -1000 to 1000.
  1111. # Because typically the initial value is 0, they will often match the
  1112. # absolute values.
  1113. oom-score-adj no
  1114. # When oom-score-adj is used, this directive controls the specific values used
  1115. # for master, replica and background child processes. Values range -2000 to
  1116. # 2000 (higher means more likely to be killed).
  1117. #
  1118. # Unprivileged processes (not root, and without CAP_SYS_RESOURCE capabilities)
  1119. # can freely increase their value, but not decrease it below its initial
  1120. # settings. This means that setting oom-score-adj to "relative" and setting the
  1121. # oom-score-adj-values to positive values will always succeed.
  1122. oom-score-adj-values 0 200 800
  1123. #################### KERNEL transparent hugepage CONTROL ######################
  1124. # Usually the kernel Transparent Huge Pages control is set to "madvise" or
  1125. # or "never" by default (/sys/kernel/mm/transparent_hugepage/enabled), in which
  1126. # case this config has no effect. On systems in which it is set to "always",
  1127. # redis will attempt to disable it specifically for the redis process in order
  1128. # to avoid latency problems specifically with fork(2) and CoW.
  1129. # If for some reason you prefer to keep it enabled, you can set this config to
  1130. # "no" and the kernel global to "always".
  1131. disable-thp yes
  1132. ############################## APPEND ONLY MODE ###############################
  1133. # By default Redis asynchronously dumps the dataset on disk. This mode is
  1134. # good enough in many applications, but an issue with the Redis process or
  1135. # a power outage may result into a few minutes of writes lost (depending on
  1136. # the configured save points).
  1137. #
  1138. # The Append Only File is an alternative persistence mode that provides
  1139. # much better durability. For instance using the default data fsync policy
  1140. # (see later in the config file) Redis can lose just one second of writes in a
  1141. # dramatic event like a server power outage, or a single write if something
  1142. # wrong with the Redis process itself happens, but the operating system is
  1143. # still running correctly.
  1144. #
  1145. # AOF and RDB persistence can be enabled at the same time without problems.
  1146. # If the AOF is enabled on startup Redis will load the AOF, that is the file
  1147. # with the better durability guarantees.
  1148. #
  1149. # Please check https://redis.io/topics/persistence for more information.
  1150. appendonly no
  1151. # The name of the append only file (default: "appendonly.aof")
  1152. appendfilename "appendonly.aof"
  1153. # The fsync() call tells the Operating System to actually write data on disk
  1154. # instead of waiting for more data in the output buffer. Some OS will really flush
  1155. # data on disk, some other OS will just try to do it ASAP.
  1156. #
  1157. # Redis supports three different modes:
  1158. #
  1159. # no: don't fsync, just let the OS flush the data when it wants. Faster.
  1160. # always: fsync after every write to the append only log. Slow, Safest.
  1161. # everysec: fsync only one time every second. Compromise.
  1162. #
  1163. # The default is "everysec", as that's usually the right compromise between
  1164. # speed and data safety. It's up to you to understand if you can relax this to
  1165. # "no" that will let the operating system flush the output buffer when
  1166. # it wants, for better performances (but if you can live with the idea of
  1167. # some data loss consider the default persistence mode that's snapshotting),
  1168. # or on the contrary, use "always" that's very slow but a bit safer than
  1169. # everysec.
  1170. #
  1171. # More details please check the following article:
  1172. # http://antirez.com/post/redis-persistence-demystified.html
  1173. #
  1174. # If unsure, use "everysec".
  1175. # appendfsync always
  1176. appendfsync everysec
  1177. # appendfsync no
  1178. # When the AOF fsync policy is set to always or everysec, and a background
  1179. # saving process (a background save or AOF log background rewriting) is
  1180. # performing a lot of I/O against the disk, in some Linux configurations
  1181. # Redis may block too long on the fsync() call. Note that there is no fix for
  1182. # this currently, as even performing fsync in a different thread will block
  1183. # our synchronous write(2) call.
  1184. #
  1185. # In order to mitigate this problem it's possible to use the following option
  1186. # that will prevent fsync() from being called in the main process while a
  1187. # BGSAVE or BGREWRITEAOF is in progress.
  1188. #
  1189. # This means that while another child is saving, the durability of Redis is
  1190. # the same as "appendfsync none". In practical terms, this means that it is
  1191. # possible to lose up to 30 seconds of log in the worst scenario (with the
  1192. # default Linux settings).
  1193. #
  1194. # If you have latency problems turn this to "yes". Otherwise leave it as
  1195. # "no" that is the safest pick from the point of view of durability.
  1196. no-appendfsync-on-rewrite no
  1197. # Automatic rewrite of the append only file.
  1198. # Redis is able to automatically rewrite the log file implicitly calling
  1199. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
  1200. #
  1201. # This is how it works: Redis remembers the size of the AOF file after the
  1202. # latest rewrite (if no rewrite has happened since the restart, the size of
  1203. # the AOF at startup is used).
  1204. #
  1205. # This base size is compared to the current size. If the current size is
  1206. # bigger than the specified percentage, the rewrite is triggered. Also
  1207. # you need to specify a minimal size for the AOF file to be rewritten, this
  1208. # is useful to avoid rewriting the AOF file even if the percentage increase
  1209. # is reached but it is still pretty small.
  1210. #
  1211. # Specify a percentage of zero in order to disable the automatic AOF
  1212. # rewrite feature.
  1213. auto-aof-rewrite-percentage 100
  1214. auto-aof-rewrite-min-size 64mb
  1215. # An AOF file may be found to be truncated at the end during the Redis
  1216. # startup process, when the AOF data gets loaded back into memory.
  1217. # This may happen when the system where Redis is running
  1218. # crashes, especially when an ext4 filesystem is mounted without the
  1219. # data=ordered option (however this can't happen when Redis itself
  1220. # crashes or aborts but the operating system still works correctly).
  1221. #
  1222. # Redis can either exit with an error when this happens, or load as much
  1223. # data as possible (the default now) and start if the AOF file is found
  1224. # to be truncated at the end. The following option controls this behavior.
  1225. #
  1226. # If aof-load-truncated is set to yes, a truncated AOF file is loaded and
  1227. # the Redis server starts emitting a log to inform the user of the event.
  1228. # Otherwise if the option is set to no, the server aborts with an error
  1229. # and refuses to start. When the option is set to no, the user requires
  1230. # to fix the AOF file using the "redis-check-aof" utility before to restart
  1231. # the server.
  1232. #
  1233. # Note that if the AOF file will be found to be corrupted in the middle
  1234. # the server will still exit with an error. This option only applies when
  1235. # Redis will try to read more data from the AOF file but not enough bytes
  1236. # will be found.
  1237. aof-load-truncated yes
  1238. # When rewriting the AOF file, Redis is able to use an RDB preamble in the
  1239. # AOF file for faster rewrites and recoveries. When this option is turned
  1240. # on the rewritten AOF file is composed of two different stanzas:
  1241. #
  1242. # [RDB file][AOF tail]
  1243. #
  1244. # When loading, Redis recognizes that the AOF file starts with the "REDIS"
  1245. # string and loads the prefixed RDB file, then continues loading the AOF
  1246. # tail.
  1247. aof-use-rdb-preamble yes
  1248. ################################ LUA SCRIPTING ###############################
  1249. # Max execution time of a Lua script in milliseconds.
  1250. #
  1251. # If the maximum execution time is reached Redis will log that a script is
  1252. # still in execution after the maximum allowed time and will start to
  1253. # reply to queries with an error.
  1254. #
  1255. # When a long running script exceeds the maximum execution time only the
  1256. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
  1257. # used to stop a script that did not yet call any write commands. The second
  1258. # is the only way to shut down the server in the case a write command was
  1259. # already issued by the script but the user doesn't want to wait for the natural
  1260. # termination of the script.
  1261. #
  1262. # Set it to 0 or a negative value for unlimited execution without warnings.
  1263. lua-time-limit 5000
  1264. ################################ REDIS CLUSTER ###############################
  1265. # Normal Redis instances can't be part of a Redis Cluster; only nodes that are
  1266. # started as cluster nodes can. In order to start a Redis instance as a
  1267. # cluster node enable the cluster support uncommenting the following:
  1268. #
  1269. # cluster-enabled yes
  1270. # Every cluster node has a cluster configuration file. This file is not
  1271. # intended to be edited by hand. It is created and updated by Redis nodes.
  1272. # Every Redis Cluster node requires a different cluster configuration file.
  1273. # Make sure that instances running in the same system do not have
  1274. # overlapping cluster configuration file names.
  1275. #
  1276. # cluster-config-file nodes-6379.conf
  1277. # Cluster node timeout is the amount of milliseconds a node must be unreachable
  1278. # for it to be considered in failure state.
  1279. # Most other internal time limits are a multiple of the node timeout.
  1280. #
  1281. # cluster-node-timeout 15000
  1282. # A replica of a failing master will avoid to start a failover if its data
  1283. # looks too old.
  1284. #
  1285. # There is no simple way for a replica to actually have an exact measure of
  1286. # its "data age", so the following two checks are performed:
  1287. #
  1288. # 1) If there are multiple replicas able to failover, they exchange messages
  1289. # in order to try to give an advantage to the replica with the best
  1290. # replication offset (more data from the master processed).
  1291. # Replicas will try to get their rank by offset, and apply to the start
  1292. # of the failover a delay proportional to their rank.
  1293. #
  1294. # 2) Every single replica computes the time of the last interaction with
  1295. # its master. This can be the last ping or command received (if the master
  1296. # is still in the "connected" state), or the time that elapsed since the
  1297. # disconnection with the master (if the replication link is currently down).
  1298. # If the last interaction is too old, the replica will not try to failover
  1299. # at all.
  1300. #
  1301. # The point "2" can be tuned by user. Specifically a replica will not perform
  1302. # the failover if, since the last interaction with the master, the time
  1303. # elapsed is greater than:
  1304. #
  1305. # (node-timeout * cluster-replica-validity-factor) + repl-ping-replica-period
  1306. #
  1307. # So for example if node-timeout is 30 seconds, and the cluster-replica-validity-factor
  1308. # is 10, and assuming a default repl-ping-replica-period of 10 seconds, the
  1309. # replica will not try to failover if it was not able to talk with the master
  1310. # for longer than 310 seconds.
  1311. #
  1312. # A large cluster-replica-validity-factor may allow replicas with too old data to failover
  1313. # a master, while a too small value may prevent the cluster from being able to
  1314. # elect a replica at all.
  1315. #
  1316. # For maximum availability, it is possible to set the cluster-replica-validity-factor
  1317. # to a value of 0, which means, that replicas will always try to failover the
  1318. # master regardless of the last time they interacted with the master.
  1319. # (However they'll always try to apply a delay proportional to their
  1320. # offset rank).
  1321. #
  1322. # Zero is the only value able to guarantee that when all the partitions heal
  1323. # the cluster will always be able to continue.
  1324. #
  1325. # cluster-replica-validity-factor 10
  1326. # Cluster replicas are able to migrate to orphaned masters, that are masters
  1327. # that are left without working replicas. This improves the cluster ability
  1328. # to resist to failures as otherwise an orphaned master can't be failed over
  1329. # in case of failure if it has no working replicas.
  1330. #
  1331. # Replicas migrate to orphaned masters only if there are still at least a
  1332. # given number of other working replicas for their old master. This number
  1333. # is the "migration barrier". A migration barrier of 1 means that a replica
  1334. # will migrate only if there is at least 1 other working replica for its master
  1335. # and so forth. It usually reflects the number of replicas you want for every
  1336. # master in your cluster.
  1337. #
  1338. # Default is 1 (replicas migrate only if their masters remain with at least
  1339. # one replica). To disable migration just set it to a very large value or
  1340. # set cluster-allow-replica-migration to 'no'.
  1341. # A value of 0 can be set but is useful only for debugging and dangerous
  1342. # in production.
  1343. #
  1344. # cluster-migration-barrier 1
  1345. # Turning off this option allows to use less automatic cluster configuration.
  1346. # It both disables migration to orphaned masters and migration from masters
  1347. # that became empty.
  1348. #
  1349. # Default is 'yes' (allow automatic migrations).
  1350. #
  1351. # cluster-allow-replica-migration yes
  1352. # By default Redis Cluster nodes stop accepting queries if they detect there
  1353. # is at least a hash slot uncovered (no available node is serving it).
  1354. # This way if the cluster is partially down (for example a range of hash slots
  1355. # are no longer covered) all the cluster becomes, eventually, unavailable.
  1356. # It automatically returns available as soon as all the slots are covered again.
  1357. #
  1358. # However sometimes you want the subset of the cluster which is working,
  1359. # to continue to accept queries for the part of the key space that is still
  1360. # covered. In order to do so, just set the cluster-require-full-coverage
  1361. # option to no.
  1362. #
  1363. # cluster-require-full-coverage yes
  1364. # This option, when set to yes, prevents replicas from trying to failover its
  1365. # master during master failures. However the replica can still perform a
  1366. # manual failover, if forced to do so.
  1367. #
  1368. # This is useful in different scenarios, especially in the case of multiple
  1369. # data center operations, where we want one side to never be promoted if not
  1370. # in the case of a total DC failure.
  1371. #
  1372. # cluster-replica-no-failover no
  1373. # This option, when set to yes, allows nodes to serve read traffic while the
  1374. # the cluster is in a down state, as long as it believes it owns the slots.
  1375. #
  1376. # This is useful for two cases. The first case is for when an application
  1377. # doesn't require consistency of data during node failures or network partitions.
  1378. # One example of this is a cache, where as long as the node has the data it
  1379. # should be able to serve it.
  1380. #
  1381. # The second use case is for configurations that don't meet the recommended
  1382. # three shards but want to enable cluster mode and scale later. A
  1383. # master outage in a 1 or 2 shard configuration causes a read/write outage to the
  1384. # entire cluster without this option set, with it set there is only a write outage.
  1385. # Without a quorum of masters, slot ownership will not change automatically.
  1386. #
  1387. # cluster-allow-reads-when-down no
  1388. # In order to setup your cluster make sure to read the documentation
  1389. # available at https://redis.io web site.
  1390. ########################## CLUSTER DOCKER/NAT support ########################
  1391. # In certain deployments, Redis Cluster nodes address discovery fails, because
  1392. # addresses are NAT-ted or because ports are forwarded (the typical case is
  1393. # Docker and other containers).
  1394. #
  1395. # In order to make Redis Cluster working in such environments, a static
  1396. # configuration where each node knows its public address is needed. The
  1397. # following four options are used for this scope, and are:
  1398. #
  1399. # * cluster-announce-ip
  1400. # * cluster-announce-port
  1401. # * cluster-announce-tls-port
  1402. # * cluster-announce-bus-port
  1403. #
  1404. # Each instructs the node about its address, client ports (for connections
  1405. # without and with TLS) and cluster message bus port. The information is then
  1406. # published in the header of the bus packets so that other nodes will be able to
  1407. # correctly map the address of the node publishing the information.
  1408. #
  1409. # If cluster-tls is set to yes and cluster-announce-tls-port is omitted or set
  1410. # to zero, then cluster-announce-port refers to the TLS port. Note also that
  1411. # cluster-announce-tls-port has no effect if cluster-tls is set to no.
  1412. #
  1413. # If the above options are not used, the normal Redis Cluster auto-detection
  1414. # will be used instead.
  1415. #
  1416. # Note that when remapped, the bus port may not be at the fixed offset of
  1417. # clients port + 10000, so you can specify any port and bus-port depending
  1418. # on how they get remapped. If the bus-port is not set, a fixed offset of
  1419. # 10000 will be used as usual.
  1420. #
  1421. # Example:
  1422. #
  1423. # cluster-announce-ip 10.1.1.5
  1424. # cluster-announce-tls-port 6379
  1425. # cluster-announce-port 0
  1426. # cluster-announce-bus-port 6380
  1427. ################################## SLOW LOG ###################################
  1428. # The Redis Slow Log is a system to log queries that exceeded a specified
  1429. # execution time. The execution time does not include the I/O operations
  1430. # like talking with the client, sending the reply and so forth,
  1431. # but just the time needed to actually execute the command (this is the only
  1432. # stage of command execution where the thread is blocked and can not serve
  1433. # other requests in the meantime).
  1434. #
  1435. # You can configure the slow log with two parameters: one tells Redis
  1436. # what is the execution time, in microseconds, to exceed in order for the
  1437. # command to get logged, and the other parameter is the length of the
  1438. # slow log. When a new command is logged the oldest one is removed from the
  1439. # queue of logged commands.
  1440. # The following time is expressed in microseconds, so 1000000 is equivalent
  1441. # to one second. Note that a negative number disables the slow log, while
  1442. # a value of zero forces the logging of every command.
  1443. slowlog-log-slower-than 10000
  1444. # There is no limit to this length. Just be aware that it will consume memory.
  1445. # You can reclaim memory used by the slow log with SLOWLOG RESET.
  1446. slowlog-max-len 128
  1447. ################################ LATENCY MONITOR ##############################
  1448. # The Redis latency monitoring subsystem samples different operations
  1449. # at runtime in order to collect data related to possible sources of
  1450. # latency of a Redis instance.
  1451. #
  1452. # Via the LATENCY command this information is available to the user that can
  1453. # print graphs and obtain reports.
  1454. #
  1455. # The system only logs operations that were performed in a time equal or
  1456. # greater than the amount of milliseconds specified via the
  1457. # latency-monitor-threshold configuration directive. When its value is set
  1458. # to zero, the latency monitor is turned off.
  1459. #
  1460. # By default latency monitoring is disabled since it is mostly not needed
  1461. # if you don't have latency issues, and collecting data has a performance
  1462. # impact, that while very small, can be measured under big load. Latency
  1463. # monitoring can easily be enabled at runtime using the command
  1464. # "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
  1465. latency-monitor-threshold 0
  1466. ############################# EVENT NOTIFICATION ##############################
  1467. # Redis can notify Pub/Sub clients about events happening in the key space.
  1468. # This feature is documented at https://redis.io/topics/notifications
  1469. #
  1470. # For instance if keyspace events notification is enabled, and a client
  1471. # performs a DEL operation on key "foo" stored in the Database 0, two
  1472. # messages will be published via Pub/Sub:
  1473. #
  1474. # PUBLISH __keyspace@0__:foo del
  1475. # PUBLISH __keyevent@0__:del foo
  1476. #
  1477. # It is possible to select the events that Redis will notify among a set
  1478. # of classes. Every class is identified by a single character:
  1479. #
  1480. # K Keyspace events, published with __keyspace@<db>__ prefix.
  1481. # E Keyevent events, published with __keyevent@<db>__ prefix.
  1482. # g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
  1483. # $ String commands
  1484. # l List commands
  1485. # s Set commands
  1486. # h Hash commands
  1487. # z Sorted set commands
  1488. # x Expired events (events generated every time a key expires)
  1489. # e Evicted events (events generated when a key is evicted for maxmemory)
  1490. # t Stream commands
  1491. # d Module key type events
  1492. # m Key-miss events (Note: It is not included in the 'A' class)
  1493. # A Alias for g$lshzxetd, so that the "AKE" string means all the events
  1494. # (Except key-miss events which are excluded from 'A' due to their
  1495. # unique nature).
  1496. #
  1497. # The "notify-keyspace-events" takes as argument a string that is composed
  1498. # of zero or multiple characters. The empty string means that notifications
  1499. # are disabled.
  1500. #
  1501. # Example: to enable list and generic events, from the point of view of the
  1502. # event name, use:
  1503. #
  1504. # notify-keyspace-events Elg
  1505. #
  1506. # Example 2: to get the stream of the expired keys subscribing to channel
  1507. # name __keyevent@0__:expired use:
  1508. #
  1509. # notify-keyspace-events Ex
  1510. #
  1511. # By default all notifications are disabled because most users don't need
  1512. # this feature and the feature has some overhead. Note that if you don't
  1513. # specify at least one of K or E, no events will be delivered.
  1514. notify-keyspace-events ""
  1515. ############################### GOPHER SERVER #################################
  1516. # Redis contains an implementation of the Gopher protocol, as specified in
  1517. # the RFC 1436 (https://www.ietf.org/rfc/rfc1436.txt).
  1518. #
  1519. # The Gopher protocol was very popular in the late '90s. It is an alternative
  1520. # to the web, and the implementation both server and client side is so simple
  1521. # that the Redis server has just 100 lines of code in order to implement this
  1522. # support.
  1523. #
  1524. # What do you do with Gopher nowadays? Well Gopher never *really* died, and
  1525. # lately there is a movement in order for the Gopher more hierarchical content
  1526. # composed of just plain text documents to be resurrected. Some want a simpler
  1527. # internet, others believe that the mainstream internet became too much
  1528. # controlled, and it's cool to create an alternative space for people that
  1529. # want a bit of fresh air.
  1530. #
  1531. # Anyway for the 10nth birthday of the Redis, we gave it the Gopher protocol
  1532. # as a gift.
  1533. #
  1534. # --- HOW IT WORKS? ---
  1535. #
  1536. # The Redis Gopher support uses the inline protocol of Redis, and specifically
  1537. # two kind of inline requests that were anyway illegal: an empty request
  1538. # or any request that starts with "/" (there are no Redis commands starting
  1539. # with such a slash). Normal RESP2/RESP3 requests are completely out of the
  1540. # path of the Gopher protocol implementation and are served as usual as well.
  1541. #
  1542. # If you open a connection to Redis when Gopher is enabled and send it
  1543. # a string like "/foo", if there is a key named "/foo" it is served via the
  1544. # Gopher protocol.
  1545. #
  1546. # In order to create a real Gopher "hole" (the name of a Gopher site in Gopher
  1547. # talking), you likely need a script like the following:
  1548. #
  1549. # https://github.com/antirez/gopher2redis
  1550. #
  1551. # --- SECURITY WARNING ---
  1552. #
  1553. # If you plan to put Redis on the internet in a publicly accessible address
  1554. # to server Gopher pages MAKE SURE TO SET A PASSWORD to the instance.
  1555. # Once a password is set:
  1556. #
  1557. # 1. The Gopher server (when enabled, not by default) will still serve
  1558. # content via Gopher.
  1559. # 2. However other commands cannot be called before the client will
  1560. # authenticate.
  1561. #
  1562. # So use the 'requirepass' option to protect your instance.
  1563. #
  1564. # Note that Gopher is not currently supported when 'io-threads-do-reads'
  1565. # is enabled.
  1566. #
  1567. # To enable Gopher support, uncomment the following line and set the option
  1568. # from no (the default) to yes.
  1569. #
  1570. # gopher-enabled no
  1571. ############################### ADVANCED CONFIG ###############################
  1572. # Hashes are encoded using a memory efficient data structure when they have a
  1573. # small number of entries, and the biggest entry does not exceed a given
  1574. # threshold. These thresholds can be configured using the following directives.
  1575. hash-max-ziplist-entries 512
  1576. hash-max-ziplist-value 64
  1577. # Lists are also encoded in a special way to save a lot of space.
  1578. # The number of entries allowed per internal list node can be specified
  1579. # as a fixed maximum size or a maximum number of elements.
  1580. # For a fixed maximum size, use -5 through -1, meaning:
  1581. # -5: max size: 64 Kb <-- not recommended for normal workloads
  1582. # -4: max size: 32 Kb <-- not recommended
  1583. # -3: max size: 16 Kb <-- probably not recommended
  1584. # -2: max size: 8 Kb <-- good
  1585. # -1: max size: 4 Kb <-- good
  1586. # Positive numbers mean store up to _exactly_ that number of elements
  1587. # per list node.
  1588. # The highest performing option is usually -2 (8 Kb size) or -1 (4 Kb size),
  1589. # but if your use case is unique, adjust the settings as necessary.
  1590. list-max-ziplist-size -2
  1591. # Lists may also be compressed.
  1592. # Compress depth is the number of quicklist ziplist nodes from *each* side of
  1593. # the list to *exclude* from compression. The head and tail of the list
  1594. # are always uncompressed for fast push/pop operations. Settings are:
  1595. # 0: disable all list compression
  1596. # 1: depth 1 means "don't start compressing until after 1 node into the list,
  1597. # going from either the head or tail"
  1598. # So: [head]->node->node->...->node->[tail]
  1599. # [head], [tail] will always be uncompressed; inner nodes will compress.
  1600. # 2: [head]->[next]->node->node->...->node->[prev]->[tail]
  1601. # 2 here means: don't compress head or head->next or tail->prev or tail,
  1602. # but compress all nodes between them.
  1603. # 3: [head]->[next]->[next]->node->node->...->node->[prev]->[prev]->[tail]
  1604. # etc.
  1605. list-compress-depth 0
  1606. # Sets have a special encoding in just one case: when a set is composed
  1607. # of just strings that happen to be integers in radix 10 in the range
  1608. # of 64 bit signed integers.
  1609. # The following configuration setting sets the limit in the size of the
  1610. # set in order to use this special memory saving encoding.
  1611. set-max-intset-entries 512
  1612. # Similarly to hashes and lists, sorted sets are also specially encoded in
  1613. # order to save a lot of space. This encoding is only used when the length and
  1614. # elements of a sorted set are below the following limits:
  1615. zset-max-ziplist-entries 128
  1616. zset-max-ziplist-value 64
  1617. # HyperLogLog sparse representation bytes limit. The limit includes the
  1618. # 16 bytes header. When an HyperLogLog using the sparse representation crosses
  1619. # this limit, it is converted into the dense representation.
  1620. #
  1621. # A value greater than 16000 is totally useless, since at that point the
  1622. # dense representation is more memory efficient.
  1623. #
  1624. # The suggested value is ~ 3000 in order to have the benefits of
  1625. # the space efficient encoding without slowing down too much PFADD,
  1626. # which is O(N) with the sparse encoding. The value can be raised to
  1627. # ~ 10000 when CPU is not a concern, but space is, and the data set is
  1628. # composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
  1629. hll-sparse-max-bytes 3000
  1630. # Streams macro node max size / items. The stream data structure is a radix
  1631. # tree of big nodes that encode multiple items inside. Using this configuration
  1632. # it is possible to configure how big a single node can be in bytes, and the
  1633. # maximum number of items it may contain before switching to a new node when
  1634. # appending new stream entries. If any of the following settings are set to
  1635. # zero, the limit is ignored, so for instance it is possible to set just a
  1636. # max entries limit by setting max-bytes to 0 and max-entries to the desired
  1637. # value.
  1638. stream-node-max-bytes 4096
  1639. stream-node-max-entries 100
  1640. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  1641. # order to help rehashing the main Redis hash table (the one mapping top-level
  1642. # keys to values). The hash table implementation Redis uses (see dict.c)
  1643. # performs a lazy rehashing: the more operation you run into a hash table
  1644. # that is rehashing, the more rehashing "steps" are performed, so if the
  1645. # server is idle the rehashing is never complete and some more memory is used
  1646. # by the hash table.
  1647. #
  1648. # The default is to use this millisecond 10 times every second in order to
  1649. # actively rehash the main dictionaries, freeing memory when possible.
  1650. #
  1651. # If unsure:
  1652. # use "activerehashing no" if you have hard latency requirements and it is
  1653. # not a good thing in your environment that Redis can reply from time to time
  1654. # to queries with 2 milliseconds delay.
  1655. #
  1656. # use "activerehashing yes" if you don't have such hard requirements but
  1657. # want to free memory asap when possible.
  1658. activerehashing yes
  1659. # The client output buffer limits can be used to force disconnection of clients
  1660. # that are not reading data from the server fast enough for some reason (a
  1661. # common reason is that a Pub/Sub client can't consume messages as fast as the
  1662. # publisher can produce them).
  1663. #
  1664. # The limit can be set differently for the three different classes of clients:
  1665. #
  1666. # normal -> normal clients including MONITOR clients
  1667. # replica -> replica clients
  1668. # pubsub -> clients subscribed to at least one pubsub channel or pattern
  1669. #
  1670. # The syntax of every client-output-buffer-limit directive is the following:
  1671. #
  1672. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
  1673. #
  1674. # A client is immediately disconnected once the hard limit is reached, or if
  1675. # the soft limit is reached and remains reached for the specified number of
  1676. # seconds (continuously).
  1677. # So for instance if the hard limit is 32 megabytes and the soft limit is
  1678. # 16 megabytes / 10 seconds, the client will get disconnected immediately
  1679. # if the size of the output buffers reach 32 megabytes, but will also get
  1680. # disconnected if the client reaches 16 megabytes and continuously overcomes
  1681. # the limit for 10 seconds.
  1682. #
  1683. # By default normal clients are not limited because they don't receive data
  1684. # without asking (in a push way), but just after a request, so only
  1685. # asynchronous clients may create a scenario where data is requested faster
  1686. # than it can read.
  1687. #
  1688. # Instead there is a default limit for pubsub and replica clients, since
  1689. # subscribers and replicas receive data in a push fashion.
  1690. #
  1691. # Both the hard or the soft limit can be disabled by setting them to zero.
  1692. client-output-buffer-limit normal 0 0 0
  1693. client-output-buffer-limit replica 256mb 64mb 60
  1694. client-output-buffer-limit pubsub 32mb 8mb 60
  1695. # Client query buffers accumulate new commands. They are limited to a fixed
  1696. # amount by default in order to avoid that a protocol desynchronization (for
  1697. # instance due to a bug in the client) will lead to unbound memory usage in
  1698. # the query buffer. However you can configure it here if you have very special
  1699. # needs, such us huge multi/exec requests or alike.
  1700. #
  1701. # client-query-buffer-limit 1gb
  1702. # In the Redis protocol, bulk requests, that are, elements representing single
  1703. # strings, are normally limited to 512 mb. However you can change this limit
  1704. # here, but must be 1mb or greater
  1705. #
  1706. # proto-max-bulk-len 512mb
  1707. # Redis calls an internal function to perform many background tasks, like
  1708. # closing connections of clients in timeout, purging expired keys that are
  1709. # never requested, and so forth.
  1710. #
  1711. # Not all tasks are performed with the same frequency, but Redis checks for
  1712. # tasks to perform according to the specified "hz" value.
  1713. #
  1714. # By default "hz" is set to 10. Raising the value will use more CPU when
  1715. # Redis is idle, but at the same time will make Redis more responsive when
  1716. # there are many keys expiring at the same time, and timeouts may be
  1717. # handled with more precision.
  1718. #
  1719. # The range is between 1 and 500, however a value over 100 is usually not
  1720. # a good idea. Most users should use the default of 10 and raise this up to
  1721. # 100 only in environments where very low latency is required.
  1722. hz 10
  1723. # Normally it is useful to have an HZ value which is proportional to the
  1724. # number of clients connected. This is useful in order, for instance, to
  1725. # avoid too many clients are processed for each background task invocation
  1726. # in order to avoid latency spikes.
  1727. #
  1728. # Since the default HZ value by default is conservatively set to 10, Redis
  1729. # offers, and enables by default, the ability to use an adaptive HZ value
  1730. # which will temporarily raise when there are many connected clients.
  1731. #
  1732. # When dynamic HZ is enabled, the actual configured HZ will be used
  1733. # as a baseline, but multiples of the configured HZ value will be actually
  1734. # used as needed once more clients are connected. In this way an idle
  1735. # instance will use very little CPU time while a busy instance will be
  1736. # more responsive.
  1737. dynamic-hz yes
  1738. # When a child rewrites the AOF file, if the following option is enabled
  1739. # the file will be fsync-ed every 32 MB of data generated. This is useful
  1740. # in order to commit the file to the disk more incrementally and avoid
  1741. # big latency spikes.
  1742. aof-rewrite-incremental-fsync yes
  1743. # When redis saves RDB file, if the following option is enabled
  1744. # the file will be fsync-ed every 32 MB of data generated. This is useful
  1745. # in order to commit the file to the disk more incrementally and avoid
  1746. # big latency spikes.
  1747. rdb-save-incremental-fsync yes
  1748. # Redis LFU eviction (see maxmemory setting) can be tuned. However it is a good
  1749. # idea to start with the default settings and only change them after investigating
  1750. # how to improve the performances and how the keys LFU change over time, which
  1751. # is possible to inspect via the OBJECT FREQ command.
  1752. #
  1753. # There are two tunable parameters in the Redis LFU implementation: the
  1754. # counter logarithm factor and the counter decay time. It is important to
  1755. # understand what the two parameters mean before changing them.
  1756. #
  1757. # The LFU counter is just 8 bits per key, it's maximum value is 255, so Redis
  1758. # uses a probabilistic increment with logarithmic behavior. Given the value
  1759. # of the old counter, when a key is accessed, the counter is incremented in
  1760. # this way:
  1761. #
  1762. # 1. A random number R between 0 and 1 is extracted.
  1763. # 2. A probability P is calculated as 1/(old_value*lfu_log_factor+1).
  1764. # 3. The counter is incremented only if R < P.
  1765. #
  1766. # The default lfu-log-factor is 10. This is a table of how the frequency
  1767. # counter changes with a different number of accesses with different
  1768. # logarithmic factors:
  1769. #
  1770. # +--------+------------+------------+------------+------------+------------+
  1771. # | factor | 100 hits | 1000 hits | 100K hits | 1M hits | 10M hits |
  1772. # +--------+------------+------------+------------+------------+------------+
  1773. # | 0 | 104 | 255 | 255 | 255 | 255 |
  1774. # +--------+------------+------------+------------+------------+------------+
  1775. # | 1 | 18 | 49 | 255 | 255 | 255 |
  1776. # +--------+------------+------------+------------+------------+------------+
  1777. # | 10 | 10 | 18 | 142 | 255 | 255 |
  1778. # +--------+------------+------------+------------+------------+------------+
  1779. # | 100 | 8 | 11 | 49 | 143 | 255 |
  1780. # +--------+------------+------------+------------+------------+------------+
  1781. #
  1782. # NOTE: The above table was obtained by running the following commands:
  1783. #
  1784. # redis-benchmark -n 1000000 incr foo
  1785. # redis-cli object freq foo
  1786. #
  1787. # NOTE 2: The counter initial value is 5 in order to give new objects a chance
  1788. # to accumulate hits.
  1789. #
  1790. # The counter decay time is the time, in minutes, that must elapse in order
  1791. # for the key counter to be divided by two (or decremented if it has a value
  1792. # less <= 10).
  1793. #
  1794. # The default value for the lfu-decay-time is 1. A special value of 0 means to
  1795. # decay the counter every time it happens to be scanned.
  1796. #
  1797. # lfu-log-factor 10
  1798. # lfu-decay-time 1
  1799. ########################### ACTIVE DEFRAGMENTATION #######################
  1800. #
  1801. # What is active defragmentation?
  1802. # -------------------------------
  1803. #
  1804. # Active (online) defragmentation allows a Redis server to compact the
  1805. # spaces left between small allocations and deallocations of data in memory,
  1806. # thus allowing to reclaim back memory.
  1807. #
  1808. # Fragmentation is a natural process that happens with every allocator (but
  1809. # less so with Jemalloc, fortunately) and certain workloads. Normally a server
  1810. # restart is needed in order to lower the fragmentation, or at least to flush
  1811. # away all the data and create it again. However thanks to this feature
  1812. # implemented by Oran Agra for Redis 4.0 this process can happen at runtime
  1813. # in a "hot" way, while the server is running.
  1814. #
  1815. # Basically when the fragmentation is over a certain level (see the
  1816. # configuration options below) Redis will start to create new copies of the
  1817. # values in contiguous memory regions by exploiting certain specific Jemalloc
  1818. # features (in order to understand if an allocation is causing fragmentation
  1819. # and to allocate it in a better place), and at the same time, will release the
  1820. # old copies of the data. This process, repeated incrementally for all the keys
  1821. # will cause the fragmentation to drop back to normal values.
  1822. #
  1823. # Important things to understand:
  1824. #
  1825. # 1. This feature is disabled by default, and only works if you compiled Redis
  1826. # to use the copy of Jemalloc we ship with the source code of Redis.
  1827. # This is the default with Linux builds.
  1828. #
  1829. # 2. You never need to enable this feature if you don't have fragmentation
  1830. # issues.
  1831. #
  1832. # 3. Once you experience fragmentation, you can enable this feature when
  1833. # needed with the command "CONFIG SET activedefrag yes".
  1834. #
  1835. # The configuration parameters are able to fine tune the behavior of the
  1836. # defragmentation process. If you are not sure about what they mean it is
  1837. # a good idea to leave the defaults untouched.
  1838. # Enabled active defragmentation
  1839. # activedefrag no
  1840. # Minimum amount of fragmentation waste to start active defrag
  1841. # active-defrag-ignore-bytes 100mb
  1842. # Minimum percentage of fragmentation to start active defrag
  1843. # active-defrag-threshold-lower 10
  1844. # Maximum percentage of fragmentation at which we use maximum effort
  1845. # active-defrag-threshold-upper 100
  1846. # Minimal effort for defrag in CPU percentage, to be used when the lower
  1847. # threshold is reached
  1848. # active-defrag-cycle-min 1
  1849. # Maximal effort for defrag in CPU percentage, to be used when the upper
  1850. # threshold is reached
  1851. # active-defrag-cycle-max 25
  1852. # Maximum number of set/hash/zset/list fields that will be processed from
  1853. # the main dictionary scan
  1854. # active-defrag-max-scan-fields 1000
  1855. # Jemalloc background thread for purging will be enabled by default
  1856. jemalloc-bg-thread yes
  1857. # It is possible to pin different threads and processes of Redis to specific
  1858. # CPUs in your system, in order to maximize the performances of the server.
  1859. # This is useful both in order to pin different Redis threads in different
  1860. # CPUs, but also in order to make sure that multiple Redis instances running
  1861. # in the same host will be pinned to different CPUs.
  1862. #
  1863. # Normally you can do this using the "taskset" command, however it is also
  1864. # possible to this via Redis configuration directly, both in Linux and FreeBSD.
  1865. #
  1866. # You can pin the server/IO threads, bio threads, aof rewrite child process, and
  1867. # the bgsave child process. The syntax to specify the cpu list is the same as
  1868. # the taskset command:
  1869. #
  1870. # Set redis server/io threads to cpu affinity 0,2,4,6:
  1871. # server_cpulist 0-7:2
  1872. #
  1873. # Set bio threads to cpu affinity 1,3:
  1874. # bio_cpulist 1,3
  1875. #
  1876. # Set aof rewrite child process to cpu affinity 8,9,10,11:
  1877. # aof_rewrite_cpulist 8-11
  1878. #
  1879. # Set bgsave child process to cpu affinity 1,10,11
  1880. # bgsave_cpulist 1,10-11
  1881. # In some cases redis will emit warnings and even refuse to start if it detects
  1882. # that the system is in bad state, it is possible to suppress these warnings
  1883. # by setting the following config which takes a space delimited list of warnings
  1884. # to suppress
  1885. #
  1886. # ignore-warnings ARM64-COW-BUG

这里说一个冷知识,大家估计都知道Redis的端口是6379,为什么是6379,就让作者来解释一下吧。

Appendix: how to remember the Redis port number

Today on Twitter I saw a tweet related to the ability to remember the Redis port number. There is a trick, the Redis port number, 6379, is MERZ at the phone keyboard.
Is it a coincidence that it sounds not random enough? Actually not ;) I selected 6379 because of MERZ, and not the other way around.
Everything started with Alessia Merz, an Italian Showgirl (make sure to check some (not safe for work) photo as well).
I and my friends are used to create our own slang, that is evolving since… 20 or 25 years. Well one adjective that we use consistently since 10 years is “merz”, but the meaning of the word changed so much in the course of the time.

原文地址:http://oldblog.antirez.com/post/redis-as-LRU-cache.html