Article directory
1. Configuration file
1.1 Units configure measurement units
The basic unit of measurement is defined at the beginning of the configuration file, only bytes are supported, bits are not supported; case insensitive;
1.2 In the case of multiple instances of INCLUDES, extract the common configuration file
1.3 Network related configuration
1.3.1 bind
By default, bind=127.0.0.1 can only accept access requests from this machine. If the bind parameter is not configured, access from any ip address is accepted
. If the protected-mode is set to on, then Redis only allows the response from the local machine if no bind ip is set and no password is set.
1.3.2 protected-mode
If neither the security mode nor the bind parameter is set, and the protected-mode is set to no, any client with an ip address can access the redis server
1.3.3 Port
Port number, default 6379
1.3.4 tcp-backlog In a high concurrency environment, use a high backlog value to avoid slow client connection problems
Set the backlog of tcp. The backlog is actually a connection queue. The sum of the backlog queue = the unfinished three-way handshake queue + the three-way handshake queue that has been completed.
Three-way handshake:
The client sends SYN to the server, and changes the status to SYN_SEND. If the server receives the request, it changes the status to SYN_RCVD, and puts the request in the syns queue.
The server replies SYN+ACK to the client. If the client receives the request, it changes the status to ESTABLISHED and sends ACK to the server.
The server receives the ACK, changes the status to ESTABLISHED, and puts the request from the syns queue to the accept queue.
Two queues are maintained in the Linux system kernel: syns queue and accept queue
The syns queue
is used to save the request of the semi-connection state, and its size is specified by /proc/sys/net/ipv4/tcp_max_syn_backlog, and the general default value is 512.
The accept queue
is used to save the request of the full connection state, and its size is specified by /proc/sys/net/core/somaxconn. When using the listen function, the kernel will take the comparison between the incoming backlog parameter and the system parameter somaxconn small value.
Note: To increase tcp-backlog, you need to confirm to increase the two values of /proc/sys/net/core/somaxconn and /proc/sys/net/ipv4/tcp_max_syn_backlog (128) at the same time to achieve the desired effect
1.3.5 timeout How many seconds does an idle client last before closing
0 means never close
1.3.6 tcp-keepalive is a heartbeat detection for visiting clients
It is detected every n seconds, and the unit is second. If it is set to 0, no keep-alive detection will be performed, it is recommended to set it to 60
1.4 GENERAL
1.4.1 daemonize background process running
Set to yes, the daemon starts in the background
1.4.2 pidfile The location where the pid file is stored
Each instance will generate a different pid file
1.4.3 loglevel specifies the logging level
Redis supports a total of four levels: debug, verbose, notice, warning, the default is notice
debug is used for development and testing
of varbose. Unlike debug, which records so many
notices, it is often used in production environments
. warning Only very important or serious information will be recorded in the log
The four levels are selected according to the stage of use, and the production environment chooses notice or warning
1.4.4 logfile log file name
1.4.5 databases 16
The default number of set databases is 16, and the default database is 0. You can use the SELECT command to specify the database id on the connection
1.5 SECURITY
1.5.1 Set password
1.6 CLIENTS
1.6.1 maxclients maximum number of connections
The appropriate number of connections needs to be configured in the cluster
1.7 MEMORY MANAGEMENT
1.7.1 maxmemory
It is recommended to set it, otherwise, the memory will be full and the server will be down
Sets the amount of memory that redis can use. Once the upper limit of memory usage is reached, redis will try to remove internal data, and the removal rules can be specified by maxmemory-policy.
If redis cannot remove the data in the memory according to the removal rules, or if "removal is not allowed", then redis will return an error message for those instructions that need to apply for memory, such as SET, LPUSH, etc.; for no memory application Commands, such as GET, will still respond normally.
If it is the master node redis, then when setting the upper limit of memory usage, it is necessary to reserve some memory space in the system for the synchronization queue cache.
1.7.2 maxmemory-policy
volatile-lru: use the LRU algorithm to remove keys, only for keys with an expiration time set;
allkeys-lru: use the LRU algorithm to remove keys from all collection keys
volatile-random: remove random keys from the expired collection, Only for keys with an expiration time set
allkeys-random: Remove random keys from all collection keys
volatile-ttl: Remove those keys with the smallest TTL value, that is, those keys that are about to expire recently
noeviction: Do not remove. For write operations, just return an error message (default)
1.7.3 maxmemory-samples
To set the number of samples,
generally set a number from 3 to 7. The smaller the value, the less accurate the sample, but the lower the performance consumption.
1.8 LAZY FREEING logical deletion
When using FLUSHDB and FLUSHALL to delete a database containing a large number of keys, it will cause redis to block; when cleaning expired data and eliminating data that exceeds the memory limit, if a large volume of keys is encountered, the server may be blocked. Redis 4.0 introduces the lazyfree mechanism, which can delete keys or database operations in background threads to avoid server blocking as much as possible.
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no