org.springframework.data.redis.core
Interface RedisOperations<K,V>

All Known Implementing Classes:
RedisTemplate, StringRedisTemplate

public interface RedisOperations<K,V>

Interface that specified a basic set of Redis operations, implemented by RedisTemplate. Not often used but a useful option for extensibility and testability (as it can be easily mocked or stubbed).


Method Summary
<HK,HV> BoundHashOperations<K,HK,HV>
boundHashOps(K key)
          Returns the operations performed on hash values bound to the given key.
 BoundListOperations<K,V> boundListOps(K key)
          Returns the operations performed on list values bound to the given key.
 BoundSetOperations<K,V> boundSetOps(K key)
          Returns the operations performed on set values bound to the given key.
 BoundValueOperations<K,V> boundValueOps(K key)
          Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key.
 BoundZSetOperations<K,V> boundZSetOps(K key)
          Returns the operations performed on zset values (also known as sorted sets) bound to the given key.
 void convertAndSend(String destination, Object message)
           
 void delete(Collection<K> key)
           
 void delete(K key)
           
 void discard()
           
 byte[] dump(K key)
           
 List<Object> exec()
           
 List<Object> exec(RedisSerializer<?> valueSerializer)
          Execute a transaction, using the provided RedisSerializer to deserialize any results that are byte[]s or Collections of byte[]s.
<T> T
execute(RedisCallback<T> action)
          Executes the given action within a Redis connection.
<T> T
execute(RedisScript<T> script, List<K> keys, Object... args)
          Executes the given RedisScript
<T> T
execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args)
          Executes the given RedisScript, using the provided RedisSerializers to serialize the script arguments and result.
<T> T
execute(SessionCallback<T> session)
          Executes a Redis session.
 List<Object> executePipelined(RedisCallback<?> action)
          Executes the given action object on a pipelined connection, returning the results.
 List<Object> executePipelined(RedisCallback<?> action, RedisSerializer<?> resultSerializer)
          Executes the given action object on a pipelined connection, returning the results using a dedicated serializer.
 List<Object> executePipelined(SessionCallback<?> session)
          Executes the given Redis session on a pipelined connection.
 List<Object> executePipelined(SessionCallback<?> session, RedisSerializer<?> resultSerializer)
          Executes the given Redis session on a pipelined connection, returning the results using a dedicated serializer.
 Boolean expire(K key, long timeout, TimeUnit unit)
           
 Boolean expireAt(K key, Date date)
           
 Long getExpire(K key)
           
 Long getExpire(K key, TimeUnit timeUnit)
           
 RedisSerializer<?> getHashKeySerializer()
           
 RedisSerializer<?> getHashValueSerializer()
           
 RedisSerializer<?> getKeySerializer()
           
 RedisSerializer<?> getValueSerializer()
           
 Boolean hasKey(K key)
           
 Set<K> keys(K pattern)
           
 Boolean move(K key, int dbIndex)
           
 void multi()
          '
<HK,HV> HashOperations<K,HK,HV>
opsForHash()
          Returns the operations performed on hash values.
 ListOperations<K,V> opsForList()
          Returns the operations performed on list values.
 SetOperations<K,V> opsForSet()
          Returns the operations performed on set values.
 ValueOperations<K,V> opsForValue()
          Returns the operations performed on simple values (or Strings in Redis terminology).
 ZSetOperations<K,V> opsForZSet()
          Returns the operations performed on zset values (also known as sorted sets).
 Boolean persist(K key)
           
 K randomKey()
           
 void rename(K oldKey, K newKey)
           
 Boolean renameIfAbsent(K oldKey, K newKey)
           
 void restore(K key, byte[] value, long timeToLive, TimeUnit unit)
           
 List<V> sort(SortQuery<K> query)
           
<T,S> List<T>
sort(SortQuery<K> query, BulkMapper<T,S> bulkMapper, RedisSerializer<S> resultSerializer)
           
<T> List<T>
sort(SortQuery<K> query, BulkMapper<T,V> bulkMapper)
           
 Long sort(SortQuery<K> query, K storeKey)
           
<T> List<T>
sort(SortQuery<K> query, RedisSerializer<T> resultSerializer)
           
 DataType type(K key)
           
 void unwatch()
           
 void watch(Collection<K> keys)
           
 void watch(K keys)
           
 

Method Detail

execute

<T> T execute(RedisCallback<T> action)
Executes the given action within a Redis connection. Application exceptions thrown by the action object get propagated to the caller (can only be unchecked) whenever possible. Redis exceptions are transformed into appropriate DAO ones. Allows for returning a result object, that is a domain object or a collection of domain objects. Performs automatic serialization/deserialization for the given objects to and from binary data suitable for the Redis storage. Note: Callback code is not supposed to handle transactions itself! Use an appropriate transaction manager. Generally, callback code must not touch any Connection lifecycle methods, like close, to let the template do its work.

Type Parameters:
T - return type
Parameters:
action - callback object that specifies the Redis action
Returns:
a result object returned by the action or null

execute

<T> T execute(SessionCallback<T> session)
Executes a Redis session. Allows multiple operations to be executed in the same session enabling 'transactional' capabilities through multi() and watch(Collection) operations.

Type Parameters:
T - return type
Parameters:
session - session callback
Returns:
result object returned by the action or null

executePipelined

List<Object> executePipelined(RedisCallback<?> action)
Executes the given action object on a pipelined connection, returning the results. Note that the callback cannot return a non-null value as it gets overwritten by the pipeline. This method will use the default serializers to deserialize results

Parameters:
action - callback object to execute
Returns:
list of objects returned by the pipeline

executePipelined

List<Object> executePipelined(RedisCallback<?> action,
                              RedisSerializer<?> resultSerializer)
Executes the given action object on a pipelined connection, returning the results using a dedicated serializer. Note that the callback cannot return a non-null value as it gets overwritten by the pipeline.

Parameters:
action - callback object to execute
resultSerializer - The Serializer to use for individual values or Collections of values. If any returned values are hashes, this serializer will be used to deserialize both the key and value
Returns:
list of objects returned by the pipeline

executePipelined

List<Object> executePipelined(SessionCallback<?> session)
Executes the given Redis session on a pipelined connection. Allows transactions to be pipelined. Note that the callback cannot return a non-null value as it gets overwritten by the pipeline.

Parameters:
session - Session callback
Returns:
list of objects returned by the pipeline

executePipelined

List<Object> executePipelined(SessionCallback<?> session,
                              RedisSerializer<?> resultSerializer)
Executes the given Redis session on a pipelined connection, returning the results using a dedicated serializer. Allows transactions to be pipelined. Note that the callback cannot return a non-null value as it gets overwritten by the pipeline.

Parameters:
session - Session callback
resultSerializer -
Returns:
list of objects returned by the pipeline

execute

<T> T execute(RedisScript<T> script,
              List<K> keys,
              Object... args)
Executes the given RedisScript

Parameters:
script - The script to execute
keys - Any keys that need to be passed to the script
args - Any args that need to be passed to the script
Returns:
The return value of the script or null if RedisScript.getResultType() is null, likely indicating a throw-away status reply (i.e. "OK")

execute

<T> T execute(RedisScript<T> script,
              RedisSerializer<?> argsSerializer,
              RedisSerializer<T> resultSerializer,
              List<K> keys,
              Object... args)
Executes the given RedisScript, using the provided RedisSerializers to serialize the script arguments and result.

Parameters:
script - The script to execute
argsSerializer - The RedisSerializer to use for serializing args
resultSerializer - The RedisSerializer to use for serializing the script return value
keys - Any keys that need to be passed to the script
args - Any args that need to be passed to the script
Returns:
The return value of the script or null if RedisScript.getResultType() is null, likely indicating a throw-away status reply (i.e. "OK")

hasKey

Boolean hasKey(K key)

delete

void delete(K key)

delete

void delete(Collection<K> key)

type

DataType type(K key)

keys

Set<K> keys(K pattern)

randomKey

K randomKey()

rename

void rename(K oldKey,
            K newKey)

renameIfAbsent

Boolean renameIfAbsent(K oldKey,
                       K newKey)

expire

Boolean expire(K key,
               long timeout,
               TimeUnit unit)

expireAt

Boolean expireAt(K key,
                 Date date)

persist

Boolean persist(K key)

move

Boolean move(K key,
             int dbIndex)

dump

byte[] dump(K key)

restore

void restore(K key,
             byte[] value,
             long timeToLive,
             TimeUnit unit)

getExpire

Long getExpire(K key)

getExpire

Long getExpire(K key,
               TimeUnit timeUnit)

watch

void watch(K keys)

watch

void watch(Collection<K> keys)

unwatch

void unwatch()

multi

void multi()
'


discard

void discard()

exec

List<Object> exec()

exec

List<Object> exec(RedisSerializer<?> valueSerializer)
Execute a transaction, using the provided RedisSerializer to deserialize any results that are byte[]s or Collections of byte[]s. If a result is a Map, the provided RedisSerializer will be used for both the keys and values. Other result types (Long, Boolean, etc) are left as-is in the converted results. Tuple results are automatically converted to TypedTuples.

Parameters:
valueSerializer - The RedisSerializer to use for deserializing the results of transaction exec
Returns:
The deserialized results of transaction exec

convertAndSend

void convertAndSend(String destination,
                    Object message)

opsForValue

ValueOperations<K,V> opsForValue()
Returns the operations performed on simple values (or Strings in Redis terminology).

Returns:
value operations

boundValueOps

BoundValueOperations<K,V> boundValueOps(K key)
Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key.

Parameters:
key - Redis key
Returns:
value operations bound to the given key

opsForList

ListOperations<K,V> opsForList()
Returns the operations performed on list values.

Returns:
list operations

boundListOps

BoundListOperations<K,V> boundListOps(K key)
Returns the operations performed on list values bound to the given key.

Parameters:
key - Redis key
Returns:
list operations bound to the given key

opsForSet

SetOperations<K,V> opsForSet()
Returns the operations performed on set values.

Returns:
set operations

boundSetOps

BoundSetOperations<K,V> boundSetOps(K key)
Returns the operations performed on set values bound to the given key.

Parameters:
key - Redis key
Returns:
set operations bound to the given key

opsForZSet

ZSetOperations<K,V> opsForZSet()
Returns the operations performed on zset values (also known as sorted sets).

Returns:
zset operations

boundZSetOps

BoundZSetOperations<K,V> boundZSetOps(K key)
Returns the operations performed on zset values (also known as sorted sets) bound to the given key.

Parameters:
key - Redis key
Returns:
zset operations bound to the given key.

opsForHash

<HK,HV> HashOperations<K,HK,HV> opsForHash()
Returns the operations performed on hash values.

Type Parameters:
HK - hash key (or field) type
HV - hash value type
Returns:
hash operations

boundHashOps

<HK,HV> BoundHashOperations<K,HK,HV> boundHashOps(K key)
Returns the operations performed on hash values bound to the given key.

Type Parameters:
HK - hash key (or field) type
HV - hash value type
Parameters:
key - Redis key
Returns:
hash operations bound to the given key.

sort

List<V> sort(SortQuery<K> query)

sort

<T> List<T> sort(SortQuery<K> query,
                 RedisSerializer<T> resultSerializer)

sort

<T> List<T> sort(SortQuery<K> query,
                 BulkMapper<T,V> bulkMapper)

sort

<T,S> List<T> sort(SortQuery<K> query,
                   BulkMapper<T,S> bulkMapper,
                   RedisSerializer<S> resultSerializer)

sort

Long sort(SortQuery<K> query,
          K storeKey)

getValueSerializer

RedisSerializer<?> getValueSerializer()

getKeySerializer

RedisSerializer<?> getKeySerializer()

getHashKeySerializer

RedisSerializer<?> getHashKeySerializer()

getHashValueSerializer

RedisSerializer<?> getHashValueSerializer()