Introduction to Redis configuration of redis that you must know

Introduction to Redis Configuration

Knowledge Index

  • View the redis.conf configuration file
  • Commonly used configurations are introduced

1 View the redis.conf configuration file

The Redis configuration file is located in the Redis installation directory, and the file name isredis.conf

Check out the configuration command:

cat redis.conf

The configuration is shown as an example in the following figure:

image-20220226201236957

2 Commonly used configurations are introduced

2.1 Enable the daemon

Redis does not run as a daemon process by default, you can modify it through this configuration item and use yes to enable the daemon process

daemonize no

  

2.2 pidfile specifies the pid file

When Redis runs as a daemon, Redis will write the pid to the /var/run/redis.pid file by default, which can be specified by pidfilespecifying

pidfile /var/run/redis.pid

2.3 Specify Redis listening port

The default port of redis is 6379

The author explained in his own blog post why 6379 was chosen as the default port, because 6379 is the number corresponding to MERZ on the phone button, and MERZ is taken from the name of Italian singer Alessia Merz

port 6379

2.4 Binding host ip address

bind 127.0.0.1

2.5 Client idle time limit

How long the client is idle to close the connection, if it is specified as 0, it means to close the function

timeout 300

2.6 Specify the logging level

Redis supports a total of four levels: debug, verbose, notice, warning, the default is verbose

loglevel verbose

2.7 Set the number of databases

Set the number of databases, Redis provides 16 databases by default, each database has an id, from 0 to 15, they do not have a name, only an id.

databases 16

2.8 Persistence Policy Configuration

In the specified unit time, how many times of update operations occur, the data will be synchronized to the local data file, and multiple conditions can cooperate with each other

#Redis默认配置文件中提供了三个条件:
save 900 1
save 300 10
save 60 10000
#分别表示900秒(15分钟)内有1个更改,300秒(5分钟)内有10个更改以及60秒内有10000个更改。

2.9 Whether to compress data when persisting

The default is yes. If this option is turned off, the burden of CPU compression will be reduced, but at the same time, the persistent file will become larger.

rdbcompression yes

2.10 Specify the local database file name

The default is dump.rdb

dbfilename dump.rdb

2.11 Local database storage directory

Default current directory

dir ./

2.12 This machine is configured for the slav service

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

slaveof

2.13 Maximum number of client connections

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 the Redis process can open. If maxclients is set to 0, there is no limit. When the number of client connections reaches the limit, Redis will close the new connection and return the max number of clients reached error message to the client

maxclients 128

2.14 Specify Redis maximum memory limit

Specify the maximum memory limit of Redis. Redis will load data into memory when it starts up. After reaching the maximum memory, Redis will first try to clear the keys that have expired or are about to expire. After this method is processed, the maximum memory setting is still reached. Write operations will no longer be possible, but read operations will still be possible. The new vm mechanism of Redis will store the Key in memory and the Value in the swap area

maxmemory

2.15 Whether to log after each update

Redis writes data to disk asynchronously by default. If it is not turned on, it may cause data loss for a period of time during power failure. Because redis itself synchronizes data files according to the above save conditions, some data will only exist in memory for a period of time. Default is no

appendonly no

2.16 Specify the update log file name

Defaults to appendonly.aof

appendfilename appendonly.aof

2.17 Specifying update log conditions

There are 3 optional values:

#no:表示等操作系统进行数据缓存同步到磁盘(快)
#always:表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)
#everysec:表示每秒同步一次(折衷,默认值)
appendfsync everysec

2.18 Whether to enable virtual memory mechanism

Specifies whether to enable the virtual memory mechanism, the default value is no

To briefly introduce, the VM mechanism stores data in paging, and Redis swaps the pages with less access, that is, cold data, to the disk, and the pages with many accesses are automatically swapped out from the disk to the memory.

vm-enabled no

2.19 vm-max-memory

Store all data larger than vm-max-memory into virtual memory, no matter how small vm-max-memory is set, all index data are stored in memory (Redis index data is keys), that is, when vm-max When -memory is set to 0, all values ​​actually exist on disk. Default value is 0

vm-max-memory 0

  

2.20 Threshold strategy

Specifies that when a certain number or the largest element exceeds a certain threshold, a special hash algorithm is used to store

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

Guess you like

Origin blog.csdn.net/scmagic/article/details/124436723