unlink
UNLINK
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Delete a key
Added in Redis 4.0. Unlike DEL, UNLINK runs asynchronously in a background thread. For collection types with many members, it is much faster than DEL.
Performance test
A SET key with 100,000 members was deleted with DEL and with UNLINK, and SLOWLOG measured the time. The value used about 12MB of memory.
- DEL delete time: 44,217 microseconds
- UNLINK delete time: 25 microseconds
- Comparison: UNLINK is about 1700 times faster. Use this command when deleting a key with many members would hurt performance.
Internal structure
The key is deleted synchronously, and the value is freed asynchronously in another thread. If the member count is 64 or fewer, deletion is synchronous like DEL.
- unlinkCommand() <db.c>: command entry
- delGenericCommand(async) <db.c>: shared delete command, requests async delete
- dbAsyncDelete() <lazyfree.c>: async delete
- dictUnlink() <dict.c>: removes the key immediately (sync).
- lazyfreeGetFreeEffort() <lazyfree.c>: returns the member count. STRING always returns 1.
- If the member count is 64 or fewer, delete synchronously like DEL, because a background thread is slower for small values.
- bioCreateBackgroundJob(BIO_LAZY_FREE) <lazyfree.c>: if members exceed 64, free the value in a background thread.
Syntax
UNLINK key [key ...] [type]
- Available since version 4.0.0.
- Time complexity is O(1) for the command itself. Freeing the value in a background thread is O(N), where N is the member count.
- ent811: type argument added.
| Related commands | DEL |
| Clients for Java | Jedis, Lettuce, Redisson | Clients for C | Hiredis |
| << EXISTS | UNLINK | KEYS >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
