In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what is the slow query and subscription mode in Redis". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the 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, and when the threshold is exceeded, the command is recorded. [
Redis command execution flow
Send a command
Command queue
Command execution
Return the result
Among them, the execution of commands is the time of slow query statistics.
Slow query two configuration parameters
Slowlog-log-slower-than: default threshold (in milliseconds). If a "very slow" command is executed, the execution time exceeding the threshold will be recorded.
Slowlog-max-len: sets the maximum number of slow log entries to be stored
Publish and subscribe model
Redis provides publish and subscribe function, which can be used for message transmission. The publish and subscribe mechanism of Redis consists of three parts, publisher, subscriber and Channel.
Publish and subscribe function
Publish command is used to send messages.
Subscribe to a channel by using the subscribe command
Pattern matching: subscribe to multiple channels at the same time, and the command is PSUBSCRIBE
Redis expiration time processing
Active processing
Timed processing. Create a timer when setting the expiration time, and delete the operation immediately when the expiration time arrives. This operation is immediate. No matter how many expired Key or server operation is in this period, it will be deleted. It is not very friendly to CPU.
To delete periodically, to delete periodically is to set a time interval to detect whether there is an expired key in each period of time, and if so, to perform deletion.
Passive processing
When the expired key is accessed again, it will judge whether the key has expired or not. If it has expired, it will delete it and return NIL. This method is CPU-friendly and will not take up CPU on other expired key, but it is not memory-friendly. A key has expired, but it will not be deleted before it is operated, and it still takes up memory space. If a large number of expired Key is not operated again, a lot of memory space will be wasted.
The treatment of expired keys by 3.RDB and AOF
If you execute the save or bgsave command to create a RDB, the program will check the keys in the database, and expired keys will not be saved to the newly created RDB file.
When the expired key is lazy or periodically deleted, the program appends (append) a DEL command to the AOF file to explicitly record that the key has been deleted.
During AOF rewriting, the program checks the keys in the database, and expired keys are not saved to the rewritten AOF file.
Memory recovery
Noeviction: the default policy, which does not delete any data, rejects all write operations and returns a client-side error message, and Redis only responds to read operations.
Volatitle-rlu: delete the key with the timeout property set according to the LRU algorithm until enough space is freed. If there are no key objects to delete, fall back to the noeviction policy.
Allkeys-lru: delete the key according to the LRU algorithm, regardless of whether the data has set the timeout property or not, until enough space is freed.
Allkeys-random: randomly delete all keys until there is enough space available.
Volatitle-random: randomly delete expired keys until there is enough space available.
Volatitle-ttl: deletes the data that is about to expire recently based on the ttl property of the key object. If not, fall back to the noeviction policy
Thank you for reading, the above is the content of "what is the slow query and subscription mode in Redis". After the study of this article, I believe you have a deeper understanding of what the slow query and subscription mode is in Redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.