com.lordofthejars.nosqlunit.redis.embedded
Class SetDatatypeOperations

java.lang.Object
  extended by com.lordofthejars.nosqlunit.redis.embedded.ExpirationDatatypeOperations
      extended by com.lordofthejars.nosqlunit.redis.embedded.SetDatatypeOperations
All Implemented Interfaces:
RedisDatatypeOperations

public class SetDatatypeOperations
extends ExpirationDatatypeOperations
implements RedisDatatypeOperations


Nested Class Summary
 
Nested classes/interfaces inherited from class com.lordofthejars.nosqlunit.redis.embedded.ExpirationDatatypeOperations
ExpirationDatatypeOperations.TtlState
 
Field Summary
protected static String SET
           
protected  com.google.common.collect.Multimap<ByteBuffer,ByteBuffer> setElements
           
 
Fields inherited from class com.lordofthejars.nosqlunit.redis.embedded.ExpirationDatatypeOperations
expirationsInMillis, NO_EXPIRATION
 
Constructor Summary
SetDatatypeOperations()
           
 
Method Summary
 Long del(byte[]... keys)
           
 boolean exists(byte[] key)
           
 void flushAllKeys()
           
 long getNumberOfKeys()
           
 List<byte[]> keys()
           
 boolean renameKey(byte[] key, byte[] newKey)
           
 Long sadd(byte[] key, byte[]... members)
          Add the specified member to the set value stored at key.
 Long scard(byte[] key)
          Return the set cardinality (number of elements).
 Set<byte[]> sdiff(byte[]... keys)
          Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
 Long sdiffstore(byte[] dstkey, byte[]... keys)
          This command works exactly like SDIFF but instead of being returned the resulting set is stored in dstkey.
 Set<byte[]> sinter(byte[]... keys)
          Return the members of a set resulting from the intersection of all the sets hold at the specified keys.
 Long sinterstore(byte[] dstkey, byte[]... keys)
          This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as dstkey.
 Boolean sismember(byte[] key, byte[] member)
          Return 1 if member is a member of the set stored at key, otherwise 0 is returned.
 Set<byte[]> smembers(byte[] key)
          Return all the members (elements) of the set value stored at key.
 Long smove(byte[] srckey, byte[] dstkey, byte[] member)
          Move the specified member from the set at srckey to the set at dstkey.
 List<byte[]> sort(byte[] key)
           
 byte[] spop(byte[] key)
          Remove a random element from a Set returning it as return value.
 byte[] srandmember(byte[] key)
          Return a random element from a Set, without removing the element.
 Long srem(byte[] key, byte[]... members)
          Remove the specified member from the set value stored at key.
 Set<byte[]> sunion(byte[]... keys)
          Return the members of a set resulting from the union of all the sets hold at the specified keys.
 Long sunionstore(byte[] dstkey, byte[]... keys)
          This command works exactly like SUNION but instead of being returned the resulting set is stored as dstkey.
 String type()
           
 
Methods inherited from class com.lordofthejars.nosqlunit.redis.embedded.ExpirationDatatypeOperations
addExpirationAt, addExpirationTime, remainingTime, removeExpiration, renameTtlKey, timedoutState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.lordofthejars.nosqlunit.redis.embedded.RedisDatatypeOperations
addExpirationAt, addExpirationTime, remainingTime, removeExpiration, timedoutState
 

Field Detail

SET

protected static final String SET
See Also:
Constant Field Values

setElements

protected com.google.common.collect.Multimap<ByteBuffer,ByteBuffer> setElements
Constructor Detail

SetDatatypeOperations

public SetDatatypeOperations()
Method Detail

sadd

public Long sadd(byte[] key,
                 byte[]... 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.

Parameters:
key -
members -
Returns:
Integer reply, specifically: 1 if the new element was added 0 if the element was already a member of the set

scard

public Long scard(byte[] key)
Return the set cardinality (number of elements). If the key does not exist 0 is returned, like for empty sets.

Parameters:
key -
Returns:
Integer reply, specifically: the cardinality (number of elements) of the set as an integer.

sdiff

public Set<byte[]> sdiff(byte[]... keys)
Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN

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:

Parameters:
keys -
Returns:
Return the members of a set resulting from the difference between the first set provided and all the successive sets.

sdiffstore

public Long sdiffstore(byte[] dstkey,
                       byte[]... keys)
This command works exactly like SDIFF but instead of being returned the resulting set is stored in dstkey.

Parameters:
dstkey -
keys -
Returns:
Status code reply

sinter

public Set<byte[]> sinter(byte[]... 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 client 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).

Parameters:
keys -
Returns:
Multi bulk reply, specifically the list of common elements.

sinterstore

public Long sinterstore(byte[] dstkey,
                        byte[]... keys)
This commnad works exactly like SINTER but instead of being returned the resulting set is sotred as dstkey.

Parameters:
dstkey -
keys -
Returns:
Status code reply

sismember

public Boolean sismember(byte[] key,
                         byte[] member)
Return 1 if member is a member of the set stored at key, otherwise 0 is returned.

Parameters:
key -
member -
Returns:
Integer reply, specifically: 1 if the element is a member of the set 0 if the element is not a member of the set OR if the key does not exist

smembers

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

Parameters:
key -
Returns:
Multi bulk reply

smove

public Long smove(byte[] srckey,
                  byte[] dstkey,
                  byte[] 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.

Parameters:
srckey -
dstkey -
member -
Returns:
Integer reply, specifically: 1 if the element was moved 0 if the element was not found on the first set and no operation was performed

spop

public byte[] spop(byte[] 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(byte[]) command does a similar work but the returned element is not removed from the Set.

Parameters:
key -
Returns:
Bulk reply

srandmember

public byte[] srandmember(byte[] 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.

Parameters:
key -
Returns:
Bulk reply

srem

public Long srem(byte[] key,
                 byte[]... 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.

Parameters:
key -
member -
Returns:
Integer reply, specifically: 1 if the new element was removed 0 if the new element was not a member of the set

sunion

public Set<byte[]> sunion(byte[]... 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 client 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.

Parameters:
keys -
Returns:
Multi bulk reply, specifically the list of common elements.

sunionstore

public Long sunionstore(byte[] dstkey,
                        byte[]... 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.

Parameters:
dstkey -
keys -
Returns:
Status code reply

getNumberOfKeys

public long getNumberOfKeys()
Specified by:
getNumberOfKeys in interface RedisDatatypeOperations

flushAllKeys

public void flushAllKeys()
Specified by:
flushAllKeys in interface RedisDatatypeOperations

del

public Long del(byte[]... keys)
Specified by:
del in interface RedisDatatypeOperations

exists

public boolean exists(byte[] key)
Specified by:
exists in interface RedisDatatypeOperations

renameKey

public boolean renameKey(byte[] key,
                         byte[] newKey)
Specified by:
renameKey in interface RedisDatatypeOperations

keys

public List<byte[]> keys()
Specified by:
keys in interface RedisDatatypeOperations

type

public String type()
Specified by:
type in interface RedisDatatypeOperations

sort

public List<byte[]> sort(byte[] key)
Specified by:
sort in interface RedisDatatypeOperations


Copyright © 2012. All Rights Reserved.