Read Redis configuration in one article, the most fragrant configuration in history

Let those little whites who always connect abnormally to redis guide the light and avoid detours. Make a drink for those big guys who don't know how to do advanced configuration.

Basic configuration items

  1. bind: Used to set the IP address for Redis binding. By default, Redis listens to all available interfaces. If you need to specify an IP address, you can use this configuration item to set it.默认开启,连接不上的原因之一,未注释掉只能进行本地连接,不能使用工具和远程连接

  2. port: Used to set the port number for Redis listening. The default port is 6379.连接不上的可能原因之一,端口号被改掉了。当然防火墙也是重点连接不上的原因(腾讯、阿里、宝塔。。。),记得开放端口哦,要不然连不上

  3. timeout: used to set the timeout period of Redis client connection. If the client does not establish a connection with Redis within the specified time, the connection will be closed.

  4. maxclients: used to limit the number of clients connected to Redis at the same time. When the number of clients reaches the limit, Redis will no longer accept new connections.

  5. loglevel: Used to set the log level of Redis. It can be set according to needs, for example, it can be set to different levels such as debug, info, notice, and warning.

  6. logfile: used to set the path of the Redis log file. By default, Redis will output logs to standard output.

  7. databases: Used to set the number of Redis databases and their respective names. By default, there is only one database, named "db0".默认16,db分区数量。代码不配置默认连接的是db0

  8. requirepass: used to set the authentication password for Redis.默认无密码,这也是连接不上的原因之一,密码验证被开启了。

  9. notify-keyspace-events Ex :key过期监听启用配置项

AOF persistent configuration items

Redis's AOF (Append-Only File) persistence mechanism achieves the purpose of persistence by recording all write operations to the Redis database. When the Redis server restarts, the data will be restored by re-executing the commands in the AOF file.

  1. appendonly: used to enable or disable AOF persistence. If set to "yes", AOF persistence is turned on; if set to "no", AOF persistence is turned off.
  2. appendfilename: used to set the name of the AOF file. The default value is "appendonly.aof".
  3. appendfsync: Used to set the synchronization strategy for AOF files. Can choose "always", "everysec" or "no". always means that every write is synchronized, everysec means that it is synchronized every second, and no means that the operating system decides when to synchronize. The default value is "everysec".
  4. auto-aof-rewrite-percentage: Used to set the threshold for automatic AOF rewrite. When the expansion ratio of the AOF file exceeds this value, Redis will automatically perform the rewriting operation. The default value is 100, which means rewriting is triggered when the size of the AOF file is doubled after the last rewriting.
  5. auto-aof-rewrite-min-size: Used to set the minimum size of automatic AOF rewrite. Only when the size of the AOF file is larger than this value, the rewriting operation will be performed. The default value is 64MB.
  6. no-appendfsync-on-rewrite: Used to set whether to disable synchronization when performing AOF file rewriting. If set to "yes", no synchronous operations will be performed when rewriting. The default value is "yes".
  7. aof-load-truncated: Used to set whether to allow Redis to ignore commands that have errors when loading AOF files. If set to "yes", errors are ignored; if set to "no", AOF files with errors are not allowed to be loaded. The default value is "yes".
  8. aof-use-rdb-preamble: It is used to set whether the beginning of the AOF file contains the RDB format part. If set to "yes", a copy of data in RDB format will be saved at the beginning of the AOF file, which helps to speed up data loading. The default value is "no".

RDB persistent configuration items

The RDB (Remote Dictionary Base) persistence mechanism of Redis achieves persistence by saving the state of the Redis database at a certain point in time to the disk in binary format. When the Redis server needs to restore data, it can restore the data by loading the RDB file.

  1. save: Used to set the time interval and conditions for RDB persistence. You can set different combinations of time intervals and conditions. For example, "save 900 1" means that the RDB file is saved once every 900 seconds with at least 1 write operation; "save 300 10" means that every 300 seconds with at least 10 write operations Save the RDB file once.
  2. bgsave: Used to set RDB persistence in the background. If set to "yes", RDB persistence is performed in the background without blocking the main thread.
  3. rdbcompression: Used to set whether to use compression for RDB files. If set to "yes", the LZF algorithm is used for compression.
  4. rdbchecksum: Used to set whether the RDB file uses a checksum. If set to "yes", add a checksum to the RDB file.
  5. dbfilename: used to set the name of the RDB file.
  6. dir: Used to set the storage directory for RDB files.

Eliminate Policy Configuration Items

Redis provides a variety of elimination strategy configuration items to configure how to eliminate unnecessary data when the memory is insufficient.

  1. maxmemory-policy: Used to set the maximum memory usage policy of Redis. Different strategies can be selected, such as "noeviction", "lru", "allkeys-lru", "volatile-lru", "allkeys-random", "volatile-random" or "volatile-ttl".
  2. volatile-ttl: Used to set whether Redis only eliminates keys with expiration time when eliminating data. If set to "yes", only keys with an expiration time will be evicted; if set to "no", keys with an expiration time as well as keys without an expiration time may be evicted.
  3. volatile-lru: It is used to set whether Redis only eliminates keys with expiration time and uses LRU algorithm when eliminating data. If set to "yes", only keys with an expiration time will be evicted and the LRU algorithm will be used; if set to "no", keys with an expiration time as well as keys without an expiration time may be evicted.
  4. volatile-random: It is used to set whether Redis only eliminates keys with expiration time and randomly selects keys to be eliminated when eliminating data. If set to "yes", only keys with an expiration time will be evicted and keys to be evicted are chosen randomly; if set to "no", keys with an expiration time as well as keys without an expiration time may be evicted.
  5. allkeys-lru: Used to set whether Redis uses the LRU algorithm to eliminate all keys when eliminating data. If set to "yes", all keys will be eliminated using the LRU algorithm; if set to "no", keys with an expiration time and keys without an expiration time may be eliminated.
  6. allkeys-random: Used to set whether Redis randomly selects keys to be eliminated when eliminating data. If set to "yes", keys to be evicted are chosen randomly; if set to "no", no keys are evicted.
  7. noeviction: Used to set Redis to prohibit the elimination of any keys when the memory is insufficient. If set to "yes", disables eviction of any keys; if set to "no", eviction occurs according to the above policy.

Master-slave replication configuration items

Redis supports master-slave replication, which can achieve high data availability and read-write separation. =

  1. replication-role: used to set the role of the Redis node. Set to "master" if the node is a master, or "slave" if the node is a slave.
  2. master-host: used to set the IP address of the master node.
  3. master-port: used to set the port number of the master node.
  4. master-auth-password: used to set the authentication password of the master node.
  5. slave-announce: Used to set whether to announce the slave node. If set to "yes", the slave node is declared; if set to "no", the slave node is not declared.
  6. slave-read-only: Used to set whether the slave node is read-only. If set to "yes", the slave node is read-only; if set to "no", the slave node is writable.
  7. slave-priority: used to set the priority of the slave node. The slave node with higher priority is more likely to be elected as the master node.
  8. replica-read-only: Used to set whether the slave node is read-only. If set to "yes", the slave node is read-only; if set to "no", the slave node is writable. This configuration item is more specific than slave-read-only and has a higher priority.
  9. replica-priority: used to set the priority of the slave node. The slave node with higher priority is more likely to be elected as the master node.
  10. replica-announce: Used to set whether to announce the slave node. If set to "yes", the slave node is declared; if set to "no", the slave node is not declared. This configuration item is more specific than slave-announce and has a higher priority.

thank you

  • Thank you very much for reading this article from the beginning to the end, I hope the content in it can inspire and help you. If you have other questions or need further understanding, please feel free to follow my dynamics and leave a message
  • Finally, can you give the author a follow and a little like, thank you!
  • If you think it is worth collecting, you can collect it

Guess you like

Origin blog.csdn.net/qq_40673786/article/details/132485272