DatascienceGeeks
DatascienceGeeks

Reputation: 438

Redis how to clear all the elements in a set

How to clear all the elements in a set? Is there any difference in deleting a key and emptying the set? Now i am using delete

# delete a set key
conn.delete('key')

Upvotes: 1

Views: 3038

Answers (1)

for_stack
for_stack

Reputation: 22936

When all members of a set have been removed, Redis will remove the set automatically. So deleting the key has the same behavior as remove all members from the key manually.

Also, deleting the key should be much faster than remove members one-by-one, since it saves lots of Round-Trip-Time.

If the set is very large, you'd better use the UNLINK command to delete the key asynchronously to avoid blocking Redis.

Upvotes: 5

Related Questions