-
Notifications
You must be signed in to change notification settings - Fork 954
Description
The problem/use-case that the feature addresses
Currently, a key is deleted when the set is empty. Distinguishing between an empty set and a key that does not exist offers many advantages. For example, if we store SQL results in a set, an empty set can represent that a query was executed but the result was empty, whereas null might imply that we need to make a database call to store in the set.
Description of the feature
Without breaking any backward compatibilities we scan support the Empty set with set of new commands and arguments
Write commands
SADD key
Existing SADD would be modified to make members as optional, invoking SADD with only key will create an empty set.
SPOP key [count] MT → Additional argument
Add new optional argument to retain the SET if no element exist.
SREMMT key member [member ...] → [New Command]
Same as SREM would keep the empty set once all members are removed.
SMOVEMT , SINTERSTOREMT, SDIFFSTOREMT, and SUNIONSTOREMT would be implemented as followups if needed. One can delete the empty set using DEL command.
Read commands
SCARD would still return 0 for empty set. To distinguish empty set from a non existing key one can use EXISTS followed by SCARD. Same can be approach for the SISMEMBER and SMISMEMBER.
SMEMBERSMT key → [New Command]
Similar to SMEMBERS but will return null when key does not exist. This command can be achieved by using EXISTS + SMEMBERS but would be supported for ease of use.
Alternatives you've considered
Provide a new param to change the default behavior.