清空/删除 Redis 中的集合? [英] Empty/delete a set in Redis?

查看:118
本文介绍了清空/删除 Redis 中的集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我只是瞎了眼,但我在 Redis 中没有看到明确的 set 命令清空现有集合(不清空整个数据库).就目前而言,我正在与自身做一个集合差异并将其存储回自身:

Maybe I'm just blind, but I don't see an explicit set command in Redis for emptying an existing set (without emptying the entire database). For the time being, I'm doing a set difference on the set with itself and storing it back into itself:

redis> SMEMBERS metasyn
1) "foo"
2) "bar"
redis> SDIFFSTORE metasyn metasyn metasyn
(integer) 0
redis> SMEMBERS metasyn
(empty list or set)

但这看起来有点傻……有更好的方法吗?

But that looks a little silly... is there a better way to do this?

推荐答案

你可以用 DEL 彻底删除集合.

You could delete the set altogether with DEL.

DEL metasyn

从 redis 控制台,

From redis console,

redis> SMEMBERS metasyn
1) "foo"
2) "bar"
redis> DEL metasyn
(integer) 1
redis> SMEMBERS metasyn
(empty list or set)

这篇关于清空/删除 Redis 中的集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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