Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

A lot of small partners have come to private letter “urge more”, today it came!

In previous articles we have explained the concepts and basic commands of Redis, today we will look at its configuration file, Redis configuration file plays a very important role in our development and practical application.

Conf configuration file can be found in the installation directory, through the vim command to view, in order to prevent changes to the configuration file, you must back up before using!

The Redis version of this article is 5.0.7

UNITS

1k => 1000 bytes
1kb => 1024 bytes
1m => 1000000 bytes
1mb => 1024*1024 bytes
1g => 1000000000 bytes
1gb => 1024*1024*1024 bytes
Copy the code

The unit is case insensitive and supports only bytes

INCLUDES

Similar to structs2 configuration files, they can be included through includes. Redis. Conf can be used as a master gate, including other.

include /path/to/local.conf
include /path/to/other.conf
Copy the code

MODULES

loadmodule /path/to/my_module.so
loadmodule /path/to/other_module.so
Copy the code

Redis can load modules at startup with the LoadModule option. If the server cannot load modules, the server will stop. Multiple modules can be loaded with multiple loadModule options.

NETWORK

  • The bind 127.0.0.1: By default, if the bind configuration directive is not specified,RedisWill listen for connections to all available network interfaces on the server.

You can use the “bind” configuration instruction, followed by one or more IP addresses, to listen on only one or more selected interfaces. For example, bind 192.168.1.100 10.0.0.1

When multiple bind addresses are set, Redis maintains multiple sockets, each Socket for a network interface.

  • Protected-mode yes: This option is enabled by default.

When the Redis server does not explicitly specify the network interface to listen on with the bind option and does not set a password, the Redis server will only accept connections from 127.0.0.1 and ::1 clients and Unix domain sockets.

  • port 6379: used to setRedisListen to theTCPPort number. The default value is 6379. If the value is 0, no listening is performedTCPport
  • Timeout 0: indicates the number of seconds after the connection is closed. 0 indicates that the connection is not closed
  • tcp-keepalive 300: The unit is second. If the value is 0, the system does not proceedkeepaliveCheck: 60 is recommended
  • tcp-backlog 511Set:tcpthebacklog.backlogIt’s actually a connection queue.

Backlog queue total = unfinished three-handshake queue + completed three-handshake queue

A high backlog value is required in high-concurrency environments to avoid slow client connection issues.

Note: the Linux kernel will reduce this value to the/proc/sys/net/core/somaxconn values, so you need to confirm increase somaxconn and tcp_max_syn_backlog two values to achieve the desired effect.

The above is all the content of today, if you have different opinions or better idea, welcome to contact AH Q, add AH Q can join the technical exchange group to participate in the discussion!

Background message to get Java dry goods materials: study notes and big factory interview questions