155 字
1 分钟
Redis 常用的过期时间、删除 Key 命令有哪些?
EXPIRE key seconds:设置 Key 的过期时间,单位是秒。PEXPIRE key milliseconds:设置 Key 的过期时间,单位是毫秒。TTL key:查看 Key 剩余的过期时间,单位是秒。PERSIST key:移除 Key 的过期时间。DEL key:删除 Key。UNLINK key:删除 Key,内存回收在后台异步进行。
# 1. 设置 60 秒后过期EXPIRE user:1 60
# 2. 设置 60000 毫秒后过期PEXPIRE user:1 60000
# 3. 查看剩余过期时间(秒)TTL user:1
# 4. 移除过期时间,让 Key 持续有效PERSIST user:1
# 5. 删除 KeyDEL user:1
# 6. 删除 Key,内存回收在后台异步进行UNLINK user:1 Redis 常用的过期时间、删除 Key 命令有哪些?
https://blog.xqcherry.top/posts/interview/redis/redis-key-expiration-and-deletion/