Redis UNLINK 命令跟 DEL 命令十分相似:用于删除指定的 key
。就像 DEL 一样,如果 key
不存在,则将其忽略。但是,该命令会执行命令之外的线程中执行实际的内存回收,因此它不是阻塞,而 DEL 是阻塞的。这就是命令名称的来源:UNLINK 命令只是将键与键空间断开连接。实际的删除将稍后异步进行。
语法
Redis UNLINK 命令基本语法如下:
redis 127.0.0.1:6379> UNLINK key_name
返回值
整数: 断开连接 key 的个数。
例子
redis> SET key1 "Hello"
"OK"
redis> SET key2 "World"
"OK"
redis> UNLINK key1 key2 key3
(integer) 2
redis>
可用版本>= 4.0.0.
时间复杂度: O(1) for each key removed regardless of its size. Then the command does O(N) work in a different thread in order to reclaim memory, where N is the number of allocations the deleted objects where composed of.