Empty/delete a set in Redis?

SetRedis

Set Problem Overview


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?

Set Solutions


Solution 1 - Set

You could delete the set altogether with DEL.

DEL metasyn

From redis console,

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbe VoelkerView Question on Stackoverflow
Solution 1 - SetAnuragView Answer on Stackoverflow