Performing Full Scans
There are two ways to delete a key in Redis.
- Use the DEL command to directly delete a key.
- Use commands such as EXPIRE to set a timeout on a key. After the timeout elapses, the key becomes inaccessible but is not deleted immediately because Redis is mostly single-threaded. Redis uses the following strategies to release the memory used by expired keys:
- Lazy free deletion: The deletion strategy is controlled in the main I/O event loop. Before a read/write command is executed, a function is called to check whether the key to be accessed has expired. If it has expired, it will be deleted and a response will be returned indicating that the key does not exist. If the key has not expired, the command execution resumes.
- Scheduled deletion: A time event function is executed at certain intervals. Each time the function is executed, a random collection of keys are checked, and expired keys are deleted.
To avoid prolonged blocks on the Redis main thread, not all keys are checked in each time event. Instead, a random collection of keys are checked each time. As a result, the memory used by expired keys cannot be released quickly.
DCS integrates these strategies and allows you to periodically release the memory used by expired keys. You can configure scheduled scans on the master nodes of your instances. The entire keyspace is traversed during the scans, triggering Redis to check whether the keys have expired and to remove expired keys if any.
- This function is supported only by DCS Redis 4.0 and 5.0 instances.
- By default, 1000 keys are scanned each time.
- Full scans are performed on the master node and affect the instance performance. Do not perform full scans during high-demand hours.
Procedure
- Log in to the DCS console.
- Click
in the upper left corner of the management console and select a region and a project.
Select the same region as your application service.
- In the navigation pane, choose Cache Manager.
- Click a DCS Redis instance.
- Click the Cache Analysis tab.
- On the Full Scan tab page, click Start Scanning to manually perform a full scan, or schedule daily automatic scanning.
- After the full scan task is submitted, you can view it in the task list. Figure 1 Full scan task lit
Last Article: Analyzing Big Keys and Hot Keys
Next Article: Managing IP Address Whitelist
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.