Redis configuration file details

  • 2020-05-07 20:38:34
  • OfStack

If you think Redis is an key value store, you can use it instead of MySQL. If you think of it as an cache that can be persisted, you might just use it to store some frequently accessed temporary data (instead of Memcached). In addition, Redis can be used as a lightweight message queue because it has built-in support for list data structures and PUB/SUB commands. It can also be used as a lightweight distributed locking system. Redis is short for REmote DIctionary Server. Redis explains it on the official website:


Redis is an open source, advanced key-value store.
It is often referred to as a data structure server since keys
can contain strings, hashes, lists, sets and sorted sets.

This article will cover the Redis configuration file in detail.

1. Redis does not run as a daemon by default. This configuration item can be modified to enable the daemon using yes


daemonize no

2. When run Redis daemon way, Redis default would take pid write/var run/redis pid files, can be specified by pidfile

pidfile /var/run/redis.pid

3. Specify Redis listening port, and the default port is 6379. The author explained in a blog post why 6379 was chosen as the default port, because 6379 is the corresponding number of MERZ on the phone button, while MERZ is the name of Alessia Merz

port 6379

4. Binding host address

bind 127.0.0.1

5. Close the connection after the client has been idle for a long time. If 0 is specified, this function is turned off

timeout 300

6. Specify the logging level, Redis supports a total of four levels: debug, verbose, notice, warning, verbose by default

loglevel verbose

7. Logging mode, default to standard output. If Redis is configured to run in daemon mode, and here is configured to log mode as standard output, the logs will be sent to /dev/null

logfile stdout

8. Set the number of databases, the default database is 0, you can use SELECT < dbid > The command specifies database id on the connection

databases 16

9. Specify how many times in how long, how many update operations, the data will be synchronized to the data file, can be more than one condition

save <seconds> <changes>

Three conditions are provided in the Redis default profile:

daemonize no
0
Represents one change in 900 seconds (15 minutes), 10 changes in 300 seconds (5 minutes), and 10,000 changes in 60 seconds, respectively.

10. Specify whether to compress data when storing to local database, yes is the default, Redis is LZF compression, if to save CPU time, you can turn off this option, but it will cause the database file to become huge


daemonize no
1
11. Specify the local database file name with a default value of dump.rdb

dbfilename dump.rdb

12. Specify local database directory

dir ./

13. Set the IP address and port of master service when the machine is slav service. When Redis starts, it will automatically synchronize data from master

daemonize no
4
14. When the master service is password protected, the slav service connects to the master password

daemonize no
5
15. Set the Redis connection password. If the connection password is configured, the client needs to pass AUTH when connecting to Redis < password > The command provides the password, which is turned off by default

daemonize no
6
16. Set the maximum number of client connections at the same time, the default is unlimited. The number of client connections that Redis can open at the same time is the maximum number of file descriptors that Redis process can open. When the number of client connections reaches the limit, Redis closes the new connection and returns an max number of clients reached error message to the client

daemonize no
7
17. Specify the maximum memory limit of Redis. Redis will load data into the memory when it is started. After reaching the maximum memory, Redis will first try to clear the Key that has expired or is about to expire. Redis's new vm mechanism will store Key in memory and Value in swap

daemonize no
8
18. Specify whether to log after each update operation. Redis writes data to disk asynchronously by default. Because redis itself synchronizes data files according to the above save condition, some data will only exist in memory for a period of time. The default is no

daemonize no
9
19. Specify the file name of the update log, appendonly.aof by default

pidfile /var/run/redis.pid
0
20. Specify an update log condition with three optional values:
no: means the operating system synchronizes data cache to disk (fast)
always: means that fsync() is called manually after each update operation to write data to disk (slow, safe)
everysec: 1 synchronization per second (compromise, default)

appendfsync everysec

21. Specify whether to enable the virtual memory mechanism, the default value is no. In brief introduction 1, the VM mechanism will store data in pages.

vm-enabled no

22. Virtual memory file path, default value is /tmp/ redis.swap, cannot be Shared by multiple Redis instances

vm-swap-file /tmp/redis.swap

23. Store all data larger than vm-max-memory in virtual memory. No matter how small the vm-max-memory setting is, all index data is stored in memory (keys is the index data of Redis). The default value is 0

vm-max-memory 0

24. The Redis swap file is divided into many page. One object can be saved on multiple page, but one page cannot be Shared by multiple objects. If you store large objects, you can use a larger page, or the default if you are not sure

vm-page-size 32

25. Set the number of page in the swap file, because the page table (1 type of bitmap indicating that the page is free or in use) is in memory, every 8 pages will consume 1byte of memory on disk.

vm-pages 134217728

26. Set the number of threads accessing swap files, preferably not exceeding the number of machine cores. If set to 0, all operations on swap files will be serial, which may cause a relatively long delay. The default value is 4

pidfile /var/run/redis.pid
7
27. Set whether to combine the smaller package into one package when sending reply to the client. It is enabled by default

pidfile /var/run/redis.pid
8
28. Specify a special hash algorithm to be used when the number of elements exceeding 1 or the maximum element exceeding a 1 threshold value

hash-max-zipmap-entries 64
hash-max-zipmap-value 512

29. Specify whether to activate the reset hash, which is on by default (more on Redis's hash algorithm later)

port 6379
0
30. Specify that other configuration files are included. The same configuration file can be used between multiple instances of Redis on the same host, while each instance has its own specific configuration file

port 6379
1
This article provides a complete introduction to the Redis configuration file.


Related articles: