Take the 2-minute tour ×

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

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

Else find a cron/process to clean periodically empty "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
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

> flushall
> 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.

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.

share|improve this answer
But in memory it's "(empty list or set)" is the same as "(nil)" ? Because if you run sadd x 1, then del x and smembers x : prompt (nil) –  Kakawait Dec 11 '12 at 14:35
Yes, it is the same. And btw, sadd x 1, del x and smembers x also returns "(empty list or set)" with redis-cli and Redis 2.6 –  Didier Spezia Dec 11 '12 at 15:20
I confirm what Didier said on Redis 2.2.12 just in case if you happen to have a Ubuntu 12.04 and not using version 2.6. once you srem the last item and make it empty it will remove it from the namespace. –  Maziyar Oct 13 '13 at 7:13
It would seem then that in order to expire a list, the list must first have elements. That is, one could not create an empty list, set an expiry, and then add elements later. –  einnocent Dec 31 '13 at 23:18
add comment

Your Answer


