|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.springframework.data.redis.core.RedisAccessor
org.springframework.data.redis.core.RedisTemplate<K,V>
K - the Redis key type against which the template works (usually a String)V - the Redis value type against which the template workspublic class RedisTemplate<K,V>
Helper class that simplifies Redis data access code.
Performs automatic serialization/deserialization between the given objects and the underlying binary data in the Redis store. By default, it uses Java serialization for its objects (throughJdkSerializationRedisSerializer). For String intensive
operations consider the dedicated StringRedisTemplate.
The central method is execute, supporting Redis access code implementing the RedisCallback interface.
It provides RedisConnection handling such that neither the RedisCallback implementation nor
the calling code needs to explicitly care about retrieving/closing Redis connections, or handling Connection
lifecycle exceptions. For typical single step actions, there are various convenience methods.
Once configured, this class is thread-safe.
Note that while the template is generified, it is up to the serializers/deserializers to properly convert the given Objects
to and from binary data.
This is the central class in Redis support.
StringRedisTemplate| Field Summary |
|---|
| Fields inherited from class org.springframework.data.redis.core.RedisAccessor |
|---|
logger |
| Constructor Summary | |
|---|---|
RedisTemplate()
Constructs a new RedisTemplate instance. |
|
| Method Summary | ||
|---|---|---|
void |
afterPropertiesSet()
|
|
|
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. |
|
Long |
convertAndSend(String channel,
Object message)
|
|
protected RedisConnection |
createRedisConnectionProxy(RedisConnection pm)
|
|
void |
delete(Collection<K> keys)
|
|
void |
delete(K key)
|
|
void |
discard()
|
|
List<Object> |
exec()
|
|
|
execute(RedisCallback<T> action)
Executes the given action within a Redis connection. |
|
|
execute(RedisCallback<T> action,
boolean exposeConnection)
Executes the given action object within a connection, which can be exposed or not. |
|
|
execute(RedisCallback<T> action,
boolean exposeConnection,
boolean pipeline)
Executes the given action object within a connection that can be exposed or not. |
|
|
execute(SessionCallback<T> session)
Executes a Redis session. |
|
Boolean |
expire(K key,
long timeout,
TimeUnit unit)
|
|
Boolean |
expireAt(K key,
Date date)
|
|
RedisSerializer<?> |
getDefaultSerializer()
Returns the default serializer used by this template. |
|
Long |
getExpire(K key)
|
|
RedisSerializer<?> |
getHashKeySerializer()
Returns the hashKeySerializer. |
|
RedisSerializer<?> |
getHashValueSerializer()
Returns the hashValueSerializer. |
|
RedisSerializer<?> |
getKeySerializer()
Returns the key serializer used by this template. |
|
RedisSerializer<String> |
getStringSerializer()
Returns the stringSerializer. |
|
RedisSerializer<?> |
getValueSerializer()
Returns the value serializer used by this template. |
|
Boolean |
hasKey(K key)
|
|
boolean |
isExposeConnection()
Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the default). |
|
Set<K> |
keys(K pattern)
|
|
Boolean |
move(K key,
int dbIndex)
|
|
void |
multi()
' |
|
|
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)
|
|
protected
|
postProcessResult(T result,
RedisConnection conn,
boolean existingConnection)
|
|
protected RedisConnection |
preProcessConnection(RedisConnection connection,
boolean existingConnection)
Processes the connection (before any settings are executed on it). |
|
K |
randomKey()
|
|
void |
rename(K oldKey,
K newKey)
|
|
Boolean |
renameIfAbsent(K oldKey,
K newKey)
|
|
void |
setDefaultSerializer(RedisSerializer<?> serializer)
Sets the default serializer to use for this template. |
|
void |
setExposeConnection(boolean exposeConnection)
Sets whether to expose the Redis connection to RedisCallback code. |
|
void |
setHashKeySerializer(RedisSerializer<?> hashKeySerializer)
Sets the hash key (or field) serializer to be used by this template. |
|
void |
setHashValueSerializer(RedisSerializer<?> hashValueSerializer)
Sets the hash value serializer to be used by this template. |
|
void |
setKeySerializer(RedisSerializer<?> serializer)
Sets the key serializer to be used by this template. |
|
void |
setStringSerializer(RedisSerializer<String> stringSerializer)
Sets the string value serializer to be used by this template (when the arguments or return types are always strings). |
|
void |
setValueSerializer(RedisSerializer<?> serializer)
Sets the value serializer to be used by this template. |
|
List<V> |
sort(SortQuery<K> query)
|
|
|
sort(SortQuery<K> query,
BulkMapper<T,S> bulkMapper,
RedisSerializer<S> resultSerializer)
|
|
|
sort(SortQuery<K> query,
BulkMapper<T,V> bulkMapper)
|
|
Long |
sort(SortQuery<K> query,
K storeKey)
|
|
|
sort(SortQuery<K> query,
RedisSerializer<T> resultSerializer)
|
|
DataType |
type(K key)
|
|
void |
unwatch()
|
|
void |
watch(Collection<K> keys)
|
|
void |
watch(K key)
|
|
| Methods inherited from class org.springframework.data.redis.core.RedisAccessor |
|---|
getConnectionFactory, setConnectionFactory |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public RedisTemplate()
RedisTemplate instance.
| Method Detail |
|---|
public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanafterPropertiesSet in class RedisAccessorpublic <T> T execute(RedisCallback<T> action)
RedisOperations
execute in interface RedisOperations<K,V>T - return typeaction - callback object that specifies the Redis action
public <T> T execute(RedisCallback<T> action,
boolean exposeConnection)
T - return typeaction - callback object that specifies the Redis actionexposeConnection - whether to enforce exposure of the native Redis Connection to callback code
public <T> T execute(RedisCallback<T> action,
boolean exposeConnection,
boolean pipeline)
T - return typeaction - callback object to executeexposeConnection - whether to enforce exposure of the native Redis Connection to callback codepipeline - whether to pipeline or not the connection for the execution
public <T> T execute(SessionCallback<T> session)
RedisOperationsRedisOperations.multi()
and RedisOperations.watch(Collection) operations.
execute in interface RedisOperations<K,V>T - return typesession - session callback
protected RedisConnection createRedisConnectionProxy(RedisConnection pm)
protected RedisConnection preProcessConnection(RedisConnection connection,
boolean existingConnection)
connection - redis connection
protected <T> T postProcessResult(T result,
RedisConnection conn,
boolean existingConnection)
public boolean isExposeConnection()
public void setExposeConnection(boolean exposeConnection)
RedisCallback code.
Default is "false": a proxy will be returned, suppressing quit and disconnect calls.
exposeConnection - public RedisSerializer<?> getDefaultSerializer()
public void setDefaultSerializer(RedisSerializer<?> serializer)
setStringSerializer(RedisSerializer)) are
initialized to this value unless explicitly set. Defaults to JdkSerializationRedisSerializer.
serializer - default serializer to usepublic void setKeySerializer(RedisSerializer<?> serializer)
getDefaultSerializer().
serializer - the key serializer to be used by this template.public RedisSerializer<?> getKeySerializer()
getKeySerializer in interface RedisOperations<K,V>public void setValueSerializer(RedisSerializer<?> serializer)
getDefaultSerializer().
serializer - the value serializer to be used by this template.public RedisSerializer<?> getValueSerializer()
getValueSerializer in interface RedisOperations<K,V>public RedisSerializer<?> getHashKeySerializer()
public void setHashKeySerializer(RedisSerializer<?> hashKeySerializer)
getDefaultSerializer().
hashKeySerializer - The hashKeySerializer to set.public RedisSerializer<?> getHashValueSerializer()
public void setHashValueSerializer(RedisSerializer<?> hashValueSerializer)
getDefaultSerializer().
hashValueSerializer - The hashValueSerializer to set.public RedisSerializer<String> getStringSerializer()
public void setStringSerializer(RedisSerializer<String> stringSerializer)
StringRedisSerializer.
stringSerializer - The stringValueSerializer to set.ValueOperations.get(Object, long, long)public List<Object> exec()
exec in interface RedisOperations<K,V>public void delete(K key)
delete in interface RedisOperations<K,V>public void delete(Collection<K> keys)
delete in interface RedisOperations<K,V>public Boolean hasKey(K key)
hasKey in interface RedisOperations<K,V>
public Boolean expire(K key,
long timeout,
TimeUnit unit)
expire in interface RedisOperations<K,V>
public Boolean expireAt(K key,
Date date)
expireAt in interface RedisOperations<K,V>
public Long convertAndSend(String channel,
Object message)
convertAndSend in interface RedisOperations<K,V>public Long getExpire(K key)
getExpire in interface RedisOperations<K,V>public Set<K> keys(K pattern)
keys in interface RedisOperations<K,V>public Boolean persist(K key)
persist in interface RedisOperations<K,V>
public Boolean move(K key,
int dbIndex)
move in interface RedisOperations<K,V>public K randomKey()
randomKey in interface RedisOperations<K,V>
public void rename(K oldKey,
K newKey)
rename in interface RedisOperations<K,V>
public Boolean renameIfAbsent(K oldKey,
K newKey)
renameIfAbsent in interface RedisOperations<K,V>public DataType type(K key)
type in interface RedisOperations<K,V>public void multi()
RedisOperations
multi in interface RedisOperations<K,V>public void discard()
discard in interface RedisOperations<K,V>public void watch(K key)
watch in interface RedisOperations<K,V>public void watch(Collection<K> keys)
watch in interface RedisOperations<K,V>public void unwatch()
unwatch in interface RedisOperations<K,V>public List<V> sort(SortQuery<K> query)
sort in interface RedisOperations<K,V>
public <T> List<T> sort(SortQuery<K> query,
RedisSerializer<T> resultSerializer)
sort in interface RedisOperations<K,V>
public <T> List<T> sort(SortQuery<K> query,
BulkMapper<T,V> bulkMapper)
sort in interface RedisOperations<K,V>
public <T,S> List<T> sort(SortQuery<K> query,
BulkMapper<T,S> bulkMapper,
RedisSerializer<S> resultSerializer)
sort in interface RedisOperations<K,V>
public Long sort(SortQuery<K> query,
K storeKey)
sort in interface RedisOperations<K,V>public BoundValueOperations<K,V> boundValueOps(K key)
RedisOperations
boundValueOps in interface RedisOperations<K,V>key - Redis key
public ValueOperations<K,V> opsForValue()
RedisOperations
opsForValue in interface RedisOperations<K,V>public ListOperations<K,V> opsForList()
RedisOperations
opsForList in interface RedisOperations<K,V>public BoundListOperations<K,V> boundListOps(K key)
RedisOperations
boundListOps in interface RedisOperations<K,V>key - Redis key
public BoundSetOperations<K,V> boundSetOps(K key)
RedisOperations
boundSetOps in interface RedisOperations<K,V>key - Redis key
public SetOperations<K,V> opsForSet()
RedisOperations
opsForSet in interface RedisOperations<K,V>public BoundZSetOperations<K,V> boundZSetOps(K key)
RedisOperations
boundZSetOps in interface RedisOperations<K,V>key - Redis key
public ZSetOperations<K,V> opsForZSet()
RedisOperations
opsForZSet in interface RedisOperations<K,V>public <HK,HV> BoundHashOperations<K,HK,HV> boundHashOps(K key)
RedisOperations
boundHashOps in interface RedisOperations<K,V>HK - hash key (or field) typeHV - hash value typekey - Redis key
public <HK,HV> HashOperations<K,HK,HV> opsForHash()
RedisOperations
opsForHash in interface RedisOperations<K,V>HK - hash key (or field) typeHV - hash value type
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||