Detailed analysis of the redis.conf file

redis.conf parsing

The configuration file must be used to start Redis!

Units

The capacity unit is not case-sensitive, and note: k!=kb

image-20220123202953149

includes

Multiple configuration files can be included using include

image-20220123203722750

network network

Network, indicating that the port opened when Redis starts is bound to the machine by default

bind 127.0.0.1

Redis specifies the listening port, the default is 6379

port 6379

Indicates how long (seconds) the server is idle before it is shut down. If this value is 0, it means that this function does not work

timeout 300

Whether to enable protected mode, Redis is enabled by default. If the bind IP address and Redis password are not set, the service will only run on the local machine by default.

protected-mode yes

General

Whether to run as a daemon process, that is, running in the background, generally the default is no, and it needs to be manually changed to yes, otherwise it cannot run in the background

daemonize yes

If running as a daemon process, you need to specify a pid file, which is created when Redis starts and deleted when it exits.

pidfile /var/run/redis_6379.pid # pid文件的保存位置

Configure the log level. The options for the log level are as follows:

  • debug: There is a lot of printed information, and it is mainly used for development and testing at work
  • verbose: The printed information is second only to debug, but the format is neater
  • notice: Redis default configuration, used in production environment
  • warning: only print important information like warnings and errors
loglevel notice

The name of the log file to be printed. If it is empty, it means standard output. In the mode of configuring the daemon process, the output information will be saved to /dev/null

logfile ""

Number of databases supported, 16

databases 16

SNAPSHOTTING snapshot (RDB configuration)

Chinese translation is snapshot. If the data is updated several times within the specified time, the data will be backed up synchronously to a file.

There are two ways to persist Redis, one is RDB and the other is AOF . SNAPSHOTTING is mainly aimed at RDB in Redis persistence

Redis is an in-memory database. If you do not use persistence to save data, there will be an embarrassing scene of power failure.

# 在900秒内,至少有一个key被修改(添加),就会进行持久化操作
save 900 1
# 在300秒内,至少有10个key被修改,就会进行持久化操作
save 300 10
# 在60秒内,至少有1万个key被修改,就会进行持久化操作
save 60 10000

top-writes-on-bgsave-error yes # 如果Redis在进行持久化的时候出现错误,是否停止写入,默认为是

rdbcompression yes # 是否在进行数据备份时压缩持久化文件,默认为是,这个操作会耗费CPU资源,可以设置为no

rdbchecksum yes # 在保存持久化文件的同时,对文件内容进行数据校验

dir ./ # 持久化文件保存的目录,默认保存在当前目录下

Security

image-20220123210858879

At the arrow, requirepass 密码set the login password in the format of: , which can also be achieved by using the command, but you need to save the command to save the configuration. The command format is as follows:

127.0.0.1:6379> CONFIG GET requirepass   # 查看密码设置
1) "requirepass"
2) ""
127.0.0.1:6379> CONFIG SET requirepass "123456"  # 设置密码为123456
OK
127.0.0.1:6379> set name "cjx"
OK
127.0.0.1:6379> get name "cjx"  # 没有访问权限
Invalid argument(s)
127.0.0.1:6379> AUTH "123456"  # 登录
OK
127.0.0.1:6379> get name
"cjx22"

Client client

maxclients 10000  # 最大客户端数量
maxmemory <bytes>  # 最大内存限制
maxmemory-policy noeviction # 内存达到限制值的处理策略

The default expiration policy in redis is volatile-lru.

How to set

config set maxmemory-policy volatile-lru 

maxmemory-policy tactics

# volatile-lru -> Evict(驱逐) using approximated LRU, only keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having an expire set.
# allkeys-random -> Remove a random key, any key.
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
# noeviction -> Don't evict anything, just return an error on write operations.

**1, volatile-lru: **Only perform LRU on the key with the expiration time set (default value)

2. allkeys-lru: delete the key of the lru algorithm

**3, volatile-random: ** Randomly delete the expiring key

**4, allkeys-random: ** Randomly delete

5, volatile-ttl: delete the recently expired

6, noeviction: never expire, return an error

AOF configurationinsert image description here

insert image description here

Guess you like

Origin blog.csdn.net/qq_51439643/article/details/123303160