public interface SetCommands
Modifier and Type | Method and Description |
---|---|
long |
sadd(String key,
String... members)
Add the specified member to the set value stored at key.
|
long |
scard(String key)
Return the set cardinality (number of elements).
|
Set<String> |
sdiff(String... keys)
Return the difference between the Sets stored at
keys |
long |
sdiffstore(String dstkey,
String... keys)
This command works exactly like
SDIFF but instead of being
returned the resulting set is stored in dstkey. |
Set<String> |
sinter(String... keys)
Return the members of a set resulting from the intersection of all the sets hold at the
specified keys.
|
long |
sintercard(int limit,
String... keys)
This command works exactly like
SINTER but instead of returning
the result set, it returns just the cardinality of the result. |
long |
sintercard(String... keys)
This command works exactly like
SINTER but instead of returning
the result set, it returns just the cardinality of the result. |
long |
sinterstore(String dstkey,
String... keys)
This command works exactly like
SINTER but instead of being
returned the resulting set is stored as dstkey. |
boolean |
sismember(String key,
String member)
Return true if member is a member of the set stored at key, otherwise false is returned.
|
Set<String> |
smembers(String key)
Return all the members (elements) of the set value stored at key.
|
List<Boolean> |
smismember(String key,
String... members)
Returns whether each member is a member of the set stored at key.
|
long |
smove(String srckey,
String dstkey,
String member)
Move the specified member from the set at srckey to the set at dstkey.
|
String |
spop(String key)
Remove a random element from a Set returning it as return value.
|
Set<String> |
spop(String key,
long count)
By default, the command
spop(String) pops a single member from the set. |
String |
srandmember(String key)
Return a random element from a Set, without removing the element.
|
List<String> |
srandmember(String key,
int count)
Return a random elements from a Set, without removing the elements.
|
long |
srem(String key,
String... members)
Remove the specified member from the set value stored at key.
|
default ScanResult<String> |
sscan(String key,
String cursor) |
ScanResult<String> |
sscan(String key,
String cursor,
ScanParams params) |
Set<String> |
sunion(String... keys)
Return the members of a set resulting from the union of all the sets hold at the specified
keys.
|
long |
sunionstore(String dstkey,
String... keys)
This command works exactly like
SUNION but instead of being
returned the resulting set is stored as dstkey. |
long sadd(String key, String... members)
Time complexity O(1)
key
- members
- Set<String> smembers(String key)
SINTER
.
Time complexity O(N)
key
- long srem(String key, String... members)
Time complexity O(1)
key
- members
- String spop(String key)
The srandmember(String)
command does a similar work but the returned element is
not removed from the Set.
Time complexity O(1)
key
- Set<String> spop(String key, long count)
spop(String)
pops a single member from the set.
In this command, the reply will consist of up to count members, depending on the set's cardinality.
The srandmember(String)
command does a similar work but the returned element is
not removed from the Set.
Time complexity O(N), where N is the value of the passed count
key
- count
- long scard(String key)
key
- boolean sismember(String key, String member)
Time complexity O(1)
key
- member
- true
if the element is a member of the set, false
otherwiseList<Boolean> smismember(String key, String... members)
Time complexity O(N) where N is the number of elements being checked for membership
key
- members
- String srandmember(String key)
The SPOP
command does a similar work but the returned element
is popped (removed) from the Set.
Time complexity O(1)
key
- List<String> srandmember(String key, int count)
The SPOP
command does a similar work but the returned element
is popped (removed) from the Set.
Time complexity O(1)
key
- count
- if positive, return an array of distinct elements.
If negative the behavior changes and the command is allowed to
return the same element multiple timesdefault ScanResult<String> sscan(String key, String cursor)
ScanResult<String> sscan(String key, String cursor, ScanParams params)
Set<String> sdiff(String... keys)
keys
Example:
key1 = [x, a, b, c] key2 = [c] key3 = [a, d] SDIFF key1,key2,key3 => [x, b]Non existing keys are considered like empty sets.
Time complexity O(N) with N being the total number of elements of all the sets
keys
- group of setslong sdiffstore(String dstkey, String... keys)
SDIFF
but instead of being
returned the resulting set is stored in dstkey.dstkey
- keys
- group of setsSet<String> sinter(String... keys)
LRANGE
the result is sent to
the connection as a multi-bulk reply (see the protocol specification for more information). If
just a single key is specified, then this command produces the same result as
SMEMBERS
. Actually SMEMBERS is just syntax sugar for SINTER.
Non existing keys are considered like empty sets, so if one of the keys is missing an empty set is returned (since the intersection with an empty set always is an empty set).
Time complexity O(N*M) worst case where N is the cardinality of the smallest set and M the number of sets
keys
- group of setslong sinterstore(String dstkey, String... keys)
SINTER
but instead of being
returned the resulting set is stored as dstkey.
Time complexity O(N*M) worst case where N is the cardinality of the smallest set and M the number of sets
dstkey
- keys
- group of setslong sintercard(String... keys)
SINTER
but instead of returning
the result set, it returns just the cardinality of the result. LIMIT defaults to 0 and means unlimited
Time complexity O(N*M) worst case where N is the cardinality of the smallest
keys
- group of setslong sintercard(int limit, String... keys)
SINTER
but instead of returning
the result set, it returns just the cardinality of the result.
Time complexity O(N*M) worst case where N is the cardinality of the smallest
limit
- If the intersection cardinality reaches limit partway through the computation,
the algorithm will exit and yield limit as the cardinality.keys
- group of setsSet<String> sunion(String... keys)
LRANGE
the result is sent to the
connection as a multi-bulk reply (see the protocol specification for more information). If just
a single key is specified, then this command produces the same result as
SMEMBERS
.
Non existing keys are considered like empty sets.
Time complexity O(N) where N is the total number of elements in all the provided sets
keys
- group of setslong sunionstore(String dstkey, String... keys)
SUNION
but instead of being
returned the resulting set is stored as dstkey. Any existing value in dstkey will be
over-written.
Time complexity O(N) where N is the total number of elements in all the provided sets
dstkey
- keys
- group of setslong smove(String srckey, String dstkey, String member)
If the source set does not exist or does not contain the specified element no operation is performed and zero is returned, otherwise the element is removed from the source set and added to the destination set. On success one is returned, even if the element was already present in the destination set.
An error is raised if the source or destination keys contain a non Set value.
Time complexity O(1)
srckey
- dstkey
- member
- Copyright © 2022. All rights reserved.