Interface SetCommands

All Known Subinterfaces:
JedisCommands
All Known Implementing Classes:
Jedis, JedisCluster, JedisPooled, JedisSentineled, JedisSharding, UnifiedJedis

public interface SetCommands
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    sadd(String key, String... members)
    Add the specified member to the set value stored at key.
    long
    Return the set cardinality (number of elements).
    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.
    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.
    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.
    long
    smove(String srckey, String dstkey, String member)
    Move the specified member from the set at srckey to the set at dstkey.
    spop(String key)
    Remove a random element from a Set returning it as return value.
    spop(String key, long count)
    By default, the command spop(String) pops a single member from the set.
    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.
    long
    srem(String key, String... members)
    Remove the specified member from the set value stored at key.
    sscan(String key, String cursor)
     
    sscan(String key, String cursor, ScanParams params)
     
    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.
  • Method Details

    • sadd

      long sadd(String key, String... members)
      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

      Set<String> smembers(String key)
      Return all the members (elements) of the set value stored at key. This is just syntax glue for SINTER.

      Time complexity O(N)

      Parameters:
      key -
      Returns:
      All elements of the set
    • srem

      long srem(String key, String... members)
      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

      String spop(String key)
      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

      Set<String> spop(String key, long count)
      By default, the command 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

      Parameters:
      key -
      count -
      Returns:
      The removed members
    • scard

      long scard(String key)
      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

      boolean sismember(String key, String member)
      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:
      true if the element is a member of the set, false otherwise
    • smismember

      List<Boolean> smismember(String key, String... members)
      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

      String srandmember(String key)
      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 SPOP command 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

      List<String> srandmember(String key, int count)
      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 SPOP command 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

      default ScanResult<String> sscan(String key, String cursor)
    • sscan

      ScanResult<String> sscan(String key, String cursor, ScanParams params)
    • sdiff

      Set<String> sdiff(String... keys)
      Return the difference between the Sets stored at 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

      Parameters:
      keys - group of sets
      Returns:
      The members of a set resulting from the difference between the sets
    • sdiffstore

      long sdiffstore(String dstkey, String... keys)
      This command works exactly like SDIFF but 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

      Set<String> sinter(String... keys)
      Return the members of a set resulting from the intersection of all the sets hold at the specified keys. Like in 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

      Parameters:
      keys - group of sets
      Returns:
      A set with members of the resulting set
    • sinterstore

      long sinterstore(String dstkey, String... keys)
      This command works exactly like 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

      Parameters:
      dstkey -
      keys - group of sets
      Returns:
      The number of elements in the resulting set
    • sintercard

      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. LIMIT defaults to 0 and means unlimited

      Time 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

      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.

      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

      Set<String> sunion(String... keys)
      Return the members of a set resulting from the union of all the sets hold at the specified keys. Like in 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

      Parameters:
      keys - group of sets
      Returns:
      A set with members of the resulting set
    • sunionstore

      long sunionstore(String dstkey, String... keys)
      This command works exactly like 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

      Parameters:
      dstkey -
      keys - group of sets
      Returns:
      The number of elements in the resulting set
    • smove

      long smove(String srckey, String dstkey, String member)
      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