Command builders for Redis set operations.
This module provides pure functions that build Redis SET command lists. Sets are unordered collections of unique strings, useful for membership tracking, tagging, and computing intersections, unions, and differences across collections.
Every function returns a plain list of strings (a command). To execute
a command, pass the result to Redis.command/2; to batch several
commands in a single round trip, use Redis.pipeline/2.
Examples
Adding members and retrieving a set:
iex> Redis.command(conn, Redis.Commands.Set.sadd("tags", ["elixir", "redis", "otp"]))
{:ok, 3}
iex> Redis.command(conn, Redis.Commands.Set.smembers("tags"))
{:ok, ["elixir", "redis", "otp"]}Set operations -- intersection and union:
iex> Redis.pipeline(conn, [
...> Redis.Commands.Set.sadd("set:a", ["1", "2", "3"]),
...> Redis.Commands.Set.sadd("set:b", ["2", "3", "4"]),
...> Redis.Commands.Set.sinter(["set:a", "set:b"]),
...> Redis.Commands.Set.sunion(["set:a", "set:b"])
...> ])
{:ok, [3, 3, ["2", "3"], ["1", "2", "3", "4"]]}Removing members:
iex> Redis.command(conn, Redis.Commands.Set.srem("tags", ["otp"]))
{:ok, 1}
Summary
Functions
Builds a SADD command to add one or more members to the set at key.
Builds a SDIFF command to return members in the first set that are not in any
of the subsequent sets listed in keys.
Builds a SINTER command to return the intersection of all sets in keys.
Builds a SISMEMBER command to test whether member belongs to the set at key.
Builds a SMEMBERS command to return all members of the set at key.
Builds a SREM command to remove one or more members from the set at key.
Builds a SUNION command to return the union of all sets in keys.
Functions
Builds a SADD command to add one or more members to the set at key.
Returns the number of members that were added (excluding duplicates).
Builds a SDIFF command to return members in the first set that are not in any
of the subsequent sets listed in keys.
Builds a SINTER command to return the intersection of all sets in keys.
Only members present in every listed set are returned.
Builds a SISMEMBER command to test whether member belongs to the set at key.
Returns 1 if the member exists, 0 otherwise.
Builds a SMEMBERS command to return all members of the set at key.
For large sets, consider sscan/3 instead to iterate incrementally.
Builds a SREM command to remove one or more members from the set at key.
Returns the number of members that were actually removed.
Builds a SUNION command to return the union of all sets in keys.