Redis UNLINK vs DEL: A Deep Dive into Internal Mechanics
2025-01-21

Both Redis' UNLINK and DEL commands remove keys, but their internal implementations differ. DEL synchronously deletes keys and frees memory, while UNLINK asynchronously queues the deletion for background processing. UNLINK's 'non-blocking' nature isn't absolute; it calculates the cost of deleting an object: if the cost is less than 64, it deletes synchronously; otherwise, asynchronously. The article delves into the Redis source code, explaining the implementation details of UNLINK and DEL, including key slot calculation, two-phase unlinking, and asynchronous deletion, and discusses the role of LAZYFREE_THRESHOLD.
Development