In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the method of redis data deletion, which is very detailed and has a certain reference value. Friends who are interested must finish reading it!
There are three common deletion strategies for Redis:
1. Passive deletion (lazy deletion): when reading / writing an expired Key, the lazy delete policy is triggered and the Key is deleted directly
two。 Proactive deletion (regular deletion): Redis conducts regular inspections to clean up expired Key
3. When the memory reaches the maxmemory configuration, the deletion of Key will be triggered.
Active deletion
In Redis, general operations are implemented by redis.c/serverCron, which mainly performs the following operations:
1. Update all kinds of statistics of the server, such as time, memory footprint, database footprint, etc.
two。 Clean up expired key-value pairs in the database.
3. Resize unreasonable databases.
4. Close and clean up clients with failed connections.
5. Try an AOF or RDB persistence operation.
6. If the server is the primary node, periodically synchronize the subsidiary nodes.
If you are in cluster mode, perform regular synchronization and connectivity tests on the cluster.
Redis runs serverCron as a time event, ensuring that it runs automatically at regular intervals, and because serverCron needs to run periodically while the Redis server is running, it is a cyclical time event: serverCron executes periodically until the server shuts down.
Summary
If a large number of Key expires every day in Redis (for example, tens of millions), then you must consider cleaning up the expired Key:
Increase the frequency of Redis active cleanup (by increasing the hz parameter)
The easiest way to manually clean up expired Key is to perform scan operation. The scan operation will trigger the first passive deletion. Do not forget to add count during scan operation.
The number of Key returned by the dbsize command, including expired Key
The Key returned by the randomkey command, excluding expired Key
The Key returned by the scan command, including expired Key
# Keyspace returned by the info command
Db6:keys=1034937352,expires=994731489,avg_ttl=507838502
The number of Key corresponding to keys is equal to that of dbsize
Expires refers to the number of Key with expiration time set
Avg_ttl refers to the average expiration time of a Key with an expiration time set (in milliseconds)
The above are all the contents of the method of deleting data by redis. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.