Redis“零"或“空列表或集合" [英] Redis "nil" or "empty list or set"

查看:67
本文介绍了Redis“零"或“空列表或集合"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用set"结构处理 redis.

I'm currently working with redis using "set" structure.

我想知道是否可以自动清空set"?

I want to know if it's possible to clean automatically empty "set" ?

否则找到一个 cron/进程来定期清理空的集合"

Else find a cron/process to clean periodically empty "set"

更新:

更通用的问题,(nil)"和(empty list or set)"之间存在差异(内存使用)

More generic question, there is a diff (memory usage) between "(nil)" and "(empty list or set)"

示例:

sadd x 1
srem x
smembers x
(empty list or set)

sadd x 1
del x
smembers x
(nil)

推荐答案

这已经是自动的.当一个集合为空时,它会从命名空间中移除.

This is already automatic. When a set is empty, it is removed from the namespace.

> flushall
OK
> sadd x 1 2 3
(integer) 3
> keys *
1) "x"
> srem x 1 2 3
(integer) 3
> keys *
(empty list or set)

您无需执行任何特定操作即可从此行为中受益.

You do not have to do anything specific to benefit from this behavior.

回答你的第二个问题,(nil) or (empty list or set) 只是对客户端程序的一种解释.在 Redis 服务器中,在这两种情况下,条目都已被物理删除,并且相关内存已被释放.

To answer your second question, (nil) or (empty list or set) is just an interpretation of the client program. In the Redis server, in both cases, the entry has been physically removed, and the associated memory freed.

这篇关于Redis“零"或“空列表或集合"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆