0
0
Redisquery~10 mins

DEL and UNLINK for deletion in Redis - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - DEL and UNLINK for deletion
Start
Receive DEL or UNLINK command
Check if key exists
Yes No
DEL: Remove key synchronously
UNLINK: Remove key asynchronously
Return number of keys deleted
End
The flow shows how Redis processes DEL and UNLINK commands: it checks if the key exists, then deletes it either synchronously (DEL) or asynchronously (UNLINK), and returns the count of deleted keys.
Execution Sample
Redis
DEL mykey
UNLINK mykey
Illustrates deletion of key 'mykey' using DEL (synchronous) and UNLINK (asynchronous).
Execution Table
StepCommandKey Exists?ActionResultNotes
1DEL mykeyYesRemove key synchronously1Key 'mykey' deleted immediately
2DEL mykeyNoNo action0Key 'mykey' does not exist
3UNLINK mykeyYesSchedule key removal asynchronously1Key 'mykey' marked for async deletion
4UNLINK mykeyNoNo action0Key 'mykey' does not exist
💡 Execution stops after command returns number of keys deleted or 0 if key not found
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4
mykey existenceVariesDoes not existDoes not existDeleted (async removal scheduled)Does not exist
Key Moments - 2 Insights
Why does DEL delete the key immediately but UNLINK does not?
DEL removes the key synchronously during the command execution (see Step 1), while UNLINK schedules the key for asynchronous deletion to avoid blocking Redis (see Step 3).
What happens if the key does not exist when DEL or UNLINK is called?
Both commands return 0 and do nothing if the key does not exist (see Steps 2 and 4 in the execution table).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of DEL when the key exists?
A1
B0
CError
DKey remains
💡 Hint
Check Step 1 in the execution_table under the Result column
At which step does UNLINK schedule the key for asynchronous deletion?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the Action column for UNLINK commands in the execution_table
If the key does not exist, what do both DEL and UNLINK return?
A1
B0
CError
DNull
💡 Hint
See Steps 2 and 4 in the execution_table Result column
Concept Snapshot
DEL and UNLINK remove keys in Redis.
DEL deletes keys immediately and blocks until done.
UNLINK schedules keys for asynchronous deletion to avoid blocking.
Both return the number of keys deleted (0 if none).
Use DEL for immediate removal, UNLINK for non-blocking deletion.
Full Transcript
This visual execution shows how Redis handles the DEL and UNLINK commands for deleting keys. When a command is received, Redis checks if the key exists. If it does, DEL removes the key immediately and returns 1, indicating one key deleted. UNLINK, on the other hand, schedules the key for asynchronous deletion to avoid blocking Redis, also returning 1. If the key does not exist, both commands return 0 and do nothing. The variable tracker shows the key's existence changing from present to deleted after DEL, and marked for async removal after UNLINK. Key moments clarify why DEL blocks and UNLINK does not, and what happens when keys are missing. The quiz tests understanding of these steps and results.