Home > Database > Redis > body text

What is slow query and subscription mode in Redis

青灯夜游
Release: 2021-11-15 10:50:57
forward
1533 people have browsed it

This article will introduce to you the slow query and subscription mode in Redis, I hope it will be helpful to you!

What is slow query and subscription mode in Redis

Slow query

The slow query log is the execution time of each command when the system executes the command. When it exceeds the threshold, Just record this command. [Related recommendations: Redis video tutorial]

Redis command execution process

What is slow query and subscription mode in Redis

  • Send command

  • Command queuing

  • Command execution

  • Return result

Command execution is the time for slow query statistics

Two configuration parameters for slow query

  • slowlog-log -slower-than: Preset threshold, unit is milliseconds. If a "very slow" command is executed, the execution time exceeding the threshold will be recorded.

  • slowlog-max- len: Set the maximum number of slow query logs to store

Publish and subscribe mode

Redis provides a publish and subscribe function, which can be used for message transmission , Redis's publish and subscribe mechanism consists of three parts, publisher, subscriber and Channel.

What is slow query and subscription mode in Redis

Publish and subscribe function

  • Use the publish command to send messages

What is slow query and subscription mode in Redis

    ##Subscribe to a channel using the subscribe command

What is slow query and subscription mode in Redis

    Pattern matching: subscribe to multiple channels at the same time, the command is PSUBSCRIBE

What is slow query and subscription mode in Redis

Redis expiration time processing

  • Active processing

Timing processing, create a timer when setting the expiration time, and perform the deletion operation immediately when the expiration time arrives. This operation is instant, no matter how many expired keys there are in this time period, or whether the server is running In any case, it will be deleted, which is not very friendly to the CPU.

Regular deletion. Regular deletion is to set a time interval. Each time period will detect whether there are expired keys. If there are, delete them.

  • Passive processing

When the expired key is accessed again, it will be judged whether the key has expired. If it has expired, it will be deleted and NIL will be returned. This processing method is friendly to the CPU. It will not occupy the CPU for other expired keys, but it is not friendly to memory. A key has expired, but it will not be deleted before it is operated, and it still takes up memory space. If there are a large number of expired keys that have not been operated again, it will Waste a lot of memory space.

3. RDB and AOF processing of expired keys

If you execute the save or bgsave command to create an RDB, the program will check the keys in the database, and expired keys will not is saved to the newly created RDB file.

When an expired key is lazily deleted or deleted periodically, the program will append a DEL command to the AOF file to explicitly record that the key has been deleted.

During the process of performing AOF rewriting, the program will check the keys in the database, and expired keys will not be saved in the rewritten AOF file.

Memory Recycling

noeviction: Default policy, no data will be deleted, all write operations will be rejected and client error information will be returned. At this time, Redis will only respond to read operations. .

volatitle-rlu: Delete keys with timeout attributes set according to the LRU algorithm until enough space is made. If there are no deletable key objects, fall back to the noeviction strategy.

allkeys-lru: Delete keys according to the LRU algorithm, regardless of whether the data has a timeout attribute set, until enough space is freed up.

allkeys-random: Randomly delete all keys until enough space is made.

volatitle-random: Randomly delete expired keys until enough space is made.

volatitle-ttl: Delete the most recently expired data based on the ttl attribute of the key-value object. If not, fall back to the noeviction strategy

For more programming-related knowledge, please visit:

Introduction to Programming! !

The above is the detailed content of What is slow query and subscription mode in Redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template