com.lordofthejars.nosqlunit.redis.embedded
Class HashDatatypeOperations

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

public class HashDatatypeOperations
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 HASH
           
protected  com.google.common.collect.Table<ByteBuffer,ByteBuffer,ByteBuffer> hashElements
           
 
Fields inherited from class com.lordofthejars.nosqlunit.redis.embedded.ExpirationDatatypeOperations
expirationsInMillis, NO_EXPIRATION
 
Constructor Summary
HashDatatypeOperations()
           
 
Method Summary
 Long del(byte[]... keys)
           
 boolean exists(byte[] key)
           
 void flushAllKeys()
           
 long getNumberOfKeys()
           
 Long hdel(byte[] key, byte[]... fields)
          Remove the specified field from an hash stored at key.
 Boolean hexists(byte[] key, byte[] field)
          Test for existence of a specified field in a hash.
 byte[] hget(byte[] key, byte[] field)
          If key holds a hash, retrieve the value associated to the specified field.
 Map<byte[],byte[]> hgetAll(byte[] key)
          Return all the fields and associated values in a hash.
 Long hincrBy(byte[] key, byte[] field, long value)
          Increment the number stored at field in the hash at key by value.
 Set<byte[]> hkeys(byte[] key)
          Return all the fields in a hash.
 Long hlen(byte[] key)
          Return the number of items in a hash.
 List<byte[]> hmget(byte[] key, byte[]... fields)
          Retrieve the values associated to the specified fields.
 String hmset(byte[] key, Map<byte[],byte[]> hash)
          Set the respective fields to the respective values.
 Long hset(byte[] key, byte[] field, byte[] value)
          Set the specified hash field to the specified value.
 Long hsetnx(byte[] key, byte[] field, byte[] value)
          Set the specified hash field to the specified value if the field not exists.
 List<byte[]> hvals(byte[] key)
          Return all the values in a hash.
 List<byte[]> keys()
           
 boolean renameKey(byte[] key, byte[] newKey)
           
 List<byte[]> sort(byte[] key)
           
 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

HASH

protected static final String HASH
See Also:
Constant Field Values

hashElements

protected com.google.common.collect.Table<ByteBuffer,ByteBuffer,ByteBuffer> hashElements
Constructor Detail

HashDatatypeOperations

public HashDatatypeOperations()
Method Detail

hset

public Long hset(byte[] key,
                 byte[] field,
                 byte[] value)
Set the specified hash field to the specified value.

If key does not exist, a new key holding a hash is created.

Parameters:
key -
field -
value -
Returns:
If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.

hget

public byte[] hget(byte[] key,
                   byte[] field)
If key holds a hash, retrieve the value associated to the specified field.

If the field is not found or the key does not exist, a special 'nil' value is returned.

Parameters:
key -
field -
Returns:
Bulk reply

hdel

public Long hdel(byte[] key,
                 byte[]... fields)
Remove the specified field from an hash stored at key.

Time complexity: O(1)

Parameters:
key -
fields -
Returns:
If the field was present in the hash it is deleted and 1 is returned, otherwise 0 is returned and no operation is performed.

hexists

public Boolean hexists(byte[] key,
                       byte[] field)
Test for existence of a specified field in a hash. Time complexity: O(1)

Parameters:
key -
field -
Returns:
Return 1 if the hash stored at key contains the specified field. Return 0 if the key is not found or the field is not present.

hgetAll

public Map<byte[],byte[]> hgetAll(byte[] key)
Return all the fields and associated values in a hash.

Parameters:
key -
Returns:
All the fields and values contained into a hash.

hincrBy

public Long hincrBy(byte[] key,
                    byte[] field,
                    long value)
Increment the number stored at field in the hash at key by value. If key does not exist, a new key holding a hash is created. If field does not exist or holds a string, the value is set to 0 before applying the operation. Since the value argument is signed you can use this command to perform both increments and decrements.

The range of values supported by HINCRBY is limited to 64 bit signed integers.

Parameters:
key -
field -
value -
Returns:
Integer reply The new value at field after the increment operation.

hkeys

public Set<byte[]> hkeys(byte[] key)
Return all the fields in a hash.

Parameters:
key -
Returns:
All the fields names contained into a hash.

hlen

public Long hlen(byte[] key)
Return the number of items in a hash.

Parameters:
key -
Returns:
The number of entries (fields) contained in the hash stored at key. If the specified key does not exist, 0 is returned assuming an empty hash.

hmget

public List<byte[]> hmget(byte[] key,
                          byte[]... fields)
Retrieve the values associated to the specified fields.

If some of the specified fields do not exist, nil values are returned. Non existing keys are considered like empty hashes.

Parameters:
key -
fields -
Returns:
Multi Bulk Reply specifically a list of all the values associated with the specified fields, in the same order of the request.

hmset

public String hmset(byte[] key,
                    Map<byte[],byte[]> hash)
Set the respective fields to the respective values. HMSET replaces old values with new values.

If key does not exist, a new key holding a hash is created.

Parameters:
key -
hash -
Returns:
Always OK because HMSET can't fail

hsetnx

public Long hsetnx(byte[] key,
                   byte[] field,
                   byte[] value)
Set the specified hash field to the specified value if the field not exists. Time complexity: O(1)

Parameters:
key -
field -
value -
Returns:
If the field already exists, 0 is returned, otherwise if a new field is created 1 is returned.

hvals

public List<byte[]> hvals(byte[] key)
Return all the values in a hash.

Parameters:
key -
Returns:
All the fields values contained into a hash.

getNumberOfKeys

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

flushAllKeys

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

type

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

keys

public List<byte[]> keys()
Specified by:
keys 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

sort

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


Copyright © 2012. All Rights Reserved.