Interface SetCommands
- All Known Subinterfaces:
JedisCommands
- All Known Implementing Classes:
Jedis,JedisCluster,JedisPooled,JedisSentineled,JedisSharding,UnifiedJedis
-
Method Summary
Modifier and TypeMethodDescriptionlongAdd the specified member to the set value stored at key.longReturn the set cardinality (number of elements).Return the difference between the Sets stored atkeyslongsdiffstore(String dstkey, String... keys) This command works exactly likeSDIFFbut instead of being returned the resulting set is stored in dstkey.Return the members of a set resulting from the intersection of all the sets hold at the specified keys.longsintercard(int limit, String... keys) This command works exactly likeSINTERbut instead of returning the result set, it returns just the cardinality of the result.longsintercard(String... keys) This command works exactly likeSINTERbut instead of returning the result set, it returns just the cardinality of the result.longsinterstore(String dstkey, String... keys) This command works exactly likeSINTERbut instead of being returned the resulting set is stored as dstkey.booleanReturn true if member is a member of the set stored at key, otherwise false is returned.Return all the members (elements) of the set value stored at key.smismember(String key, String... members) Returns whether each member is a member of the set stored at key.longMove the specified member from the set at srckey to the set at dstkey.Remove a random element from a Set returning it as return value.By default, the commandspop(String)pops a single member from the set.srandmember(String key) Return a random element from a Set, without removing the element.srandmember(String key, int count) Return a random elements from a Set, without removing the elements.longRemove the specified member from the set value stored at key.default ScanResult<String> sscan(String key, String cursor, ScanParams params) Return the members of a set resulting from the union of all the sets hold at the specified keys.longsunionstore(String dstkey, String... keys) This command works exactly likeSUNIONbut instead of being returned the resulting set is stored as dstkey.
-
Method Details
-
sadd
Add the specified member to the set value stored at key. If member is already a member of the set no operation is performed. If key does not exist a new set with the specified member as sole member is created. If the key exists but does not hold a set value an error is returned.Time complexity O(1)
- Parameters:
key-members-- Returns:
- The number of elements that were added to the set, not including all the elements already present in the set
-
smembers
Return all the members (elements) of the set value stored at key. This is just syntax glue forSINTER.Time complexity O(N)
- Parameters:
key-- Returns:
- All elements of the set
-
srem
Remove the specified member from the set value stored at key. If member was not a member of the set no operation is performed. If key does not hold a set value an error is returned.Time complexity O(1)
- Parameters:
key-members-- Returns:
- The number of members that were removed from the set, not including non-existing members
-
spop
Remove a random element from a Set returning it as return value. If the Set is empty or the key does not exist, a nil object is returned.The
srandmember(String)command does a similar work but the returned element is not removed from the Set.Time complexity O(1)
- Parameters:
key-- Returns:
- The removed member, or nil when key does not exist
-
spop
By default, the commandspop(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
- Parameters:
key-count-- Returns:
- The removed members
-
scard
Return the set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sets.- Parameters:
key-- Returns:
- The cardinality (number of elements) of the set
-
sismember
Return true if member is a member of the set stored at key, otherwise false is returned.Time complexity O(1)
- Parameters:
key-member-- Returns:
trueif the element is a member of the set,falseotherwise
-
smismember
Returns whether each member is a member of the set stored at key.Time complexity O(N) where N is the number of elements being checked for membership
- Parameters:
key-members-- Returns:
- List representing the membership of the given elements, in the same order as they are requested
-
srandmember
Return a random element from a Set, without removing the element. If the Set is empty or the key does not exist, a nil object is returned.The
SPOPcommand does a similar work but the returned element is popped (removed) from the Set.Time complexity O(1)
- Parameters:
key-- Returns:
- The randomly selected element
-
srandmember
Return a random elements from a Set, without removing the elements. If the Set is empty or the key does not exist, an empty list is returned.The
SPOPcommand does a similar work but the returned element is popped (removed) from the Set.Time complexity O(1)
- Parameters:
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 times- Returns:
- A list of randomly selected elements
-
sscan
-
sscan
-
sdiff
Return the difference between the Sets stored atkeysExample:
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
- Parameters:
keys- group of sets- Returns:
- The members of a set resulting from the difference between the sets
-
sdiffstore
This command works exactly likeSDIFFbut instead of being returned the resulting set is stored in dstkey.- Parameters:
dstkey-keys- group of sets- Returns:
- The number of elements in the resulting set
-
sinter
Return the members of a set resulting from the intersection of all the sets hold at the specified keys. Like inLRANGEthe 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 asSMEMBERS. 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
- Parameters:
keys- group of sets- Returns:
- A set with members of the resulting set
-
sinterstore
This command works exactly likeSINTERbut 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
- Parameters:
dstkey-keys- group of sets- Returns:
- The number of elements in the resulting set
-
sintercard
This command works exactly likeSINTERbut instead of returning the result set, it returns just the cardinality of the result. LIMIT defaults to 0 and means unlimitedTime complexity O(N*M) worst case where N is the cardinality of the smallest
- Parameters:
keys- group of sets- Returns:
- The cardinality of the set which would result from the intersection of all the given sets
-
sintercard
This command works exactly likeSINTERbut 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
- Parameters:
limit- If the intersection cardinality reaches limit partway through the computation, the algorithm will exit and yield limit as the cardinality.keys- group of sets- Returns:
- The cardinality of the set which would result from the intersection of all the given sets
-
sunion
Return the members of a set resulting from the union of all the sets hold at the specified keys. Like inLRANGEthe 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 asSMEMBERS.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
- Parameters:
keys- group of sets- Returns:
- A set with members of the resulting set
-
sunionstore
This command works exactly likeSUNIONbut 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
- Parameters:
dstkey-keys- group of sets- Returns:
- The number of elements in the resulting set
-
smove
Move the specified member from the set at srckey to the set at dstkey. This operation is atomic, in every given moment the element will appear to be in the source or destination set for accessing clients.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)
- Parameters:
srckey-dstkey-member-- Returns:
- 1 if the element was moved, 0 if no operation was performed
-