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"
UPDATE:
More generic question, there is a diff (memory usage) between "(nil)" and "(empty list or set)"
example:
sadd x 1
srem x
smembers x
(empty list or set)
or
sadd x 1
del x
smembers x
(nil)
The way to test for this in Redis is to simply query the key. If the key is empty, populate it. If it is a string use get (or exists). If it is a hash then query for the specific members you need.
To delete a large set in Redis: Rename the key to a unique, namespaced key so that the set appears “deleted” to other Redis clients immediately. Incrementally delete members from the set in small batches until it is empty.
To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.
Deleting Keys Deleting a key in Redis is as simple as creating one. We use the DEL command followed by the name of the key we wish to remove. Redis will drop the key and its associated data if the specified key exists in the data store. You can also use the DEL command to remove multiple keys in a single instance.
This is already automatic. When a set is empty, it is removed from the namespace.
> flushall
OK
> 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With