Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty/delete a set in Redis?

Tags:

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?

like image 553
Abe Voelker Avatar asked Jun 10 '11 02:06

Abe Voelker


People also ask

How do I clear all Redis data?

Redis Commands There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.

How do I clean my Redis server?

The easiest way to clear Redis cache is to use the redis-cli command. Databases in Redis are stored individually. Using the redis-cli command allows you to either clear the keys from all databases, or from a single specified database only.

Is Redis del blocking?

In Redis 4.0, there is a new command UNLINK to delete the keys in Redis memory. This command is very similar to DEL: it removes the specified keys. Just like DEL a key is ignored if it does not exist. However the command performs the actual memory reclaiming in a different thread, so it is not blocking, while DEL is.


1 Answers

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) 
like image 61
Anurag Avatar answered Oct 13 '22 10:10

Anurag