Class RedisTemplate<K,V>
- Type Parameters:
K
- the Redis key type against which the template works (usually a String)V
- the Redis value type against which the template works
- All Implemented Interfaces:
Aware
,BeanClassLoaderAware
,InitializingBean
,RedisOperations<K,
V>
- Direct Known Subclasses:
StringRedisTemplate
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 (through JdkSerializationRedisSerializer
). 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.
- Author:
- Costin Leau, Christoph Strobl, Ninad Divadkar, Anqing Shao, Mark Paluch, Denis Zavedeev, ihaohong, Chen Li, Vedran Pavic
- See Also:
-
Field Summary
Fields inherited from class org.springframework.data.redis.core.RedisAccessor
logger
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boundGeoOps
(K key) Returns geospatial specific operations interface bound to the given key.<HK,
HV> BoundHashOperations<K, HK, HV> boundHashOps
(K key) Returns the operations performed on hash values bound to the given key.boundListOps
(K key) Returns the operations performed on list values bound to the given key.boundSetOps
(K key) Returns the operations performed on set values bound to the given key.<HK,
HV> BoundStreamOperations<K, HK, HV> boundStreamOps
(K key) Returns the operations performed on Streams bound to the given key.boundValueOps
(K key) Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key.boundZSetOps
(K key) Returns the operations performed on zset values (also known as sorted sets) bound to the given key.convertAndSend
(String channel, Object message) Publishes the given message to the given channel.Copy givensourceKey
totargetKey
.countExistingKeys
(Collection<K> keys) Count the number ofkeys
that exist.protected RedisConnection
createRedisConnectionProxy
(RedisConnection connection) delete
(Collection<K> keys) Delete givenkeys
.Delete givenkey
.void
discard()
Discard all commands issued afterRedisOperations.multi()
.byte[]
Executes the Redis dump command and returns the results.exec()
Execute a transaction, using the defaultRedisSerializer
s to deserialize any results that are byte[]s or Collections or Maps of byte[]s or Tuples.exec
(RedisSerializer<?> valueSerializer) Execute a transaction, using the providedRedisSerializer
to deserialize any results that are byte[]s or Collections of byte[]s.execRaw()
<T> T
execute
(RedisCallback<T> action) Executes the given action within a Redis connection.<T> T
execute
(RedisCallback<T> action, boolean exposeConnection) Executes the given action object within a connection, which can be exposed or not.<T> T
execute
(RedisCallback<T> action, boolean exposeConnection, boolean pipeline) Executes the given action object within a connection that can be exposed or not.<T> T
execute
(RedisScript<T> script, List<K> keys, Object... args) Executes the givenRedisScript
<T> T
execute
(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args) Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.<T> T
execute
(SessionCallback<T> session) Executes a Redis session.executePipelined
(RedisCallback<?> action) Executes the given action object on a pipelined connection, returning the results.executePipelined
(RedisCallback<?> action, RedisSerializer<?> resultSerializer) Executes the given action object on a pipelined connection, returning the results using a dedicated serializer.executePipelined
(SessionCallback<?> session) Executes the given Redis session on a pipelined connection.executePipelined
(SessionCallback<?> session, RedisSerializer<?> resultSerializer) Executes the given Redis session on a pipelined connection, returning the results using a dedicated serializer.<T extends Closeable>
TexecuteWithStickyConnection
(RedisCallback<T> callback) Allocates and binds a newRedisConnection
to the actual return type of the method.Set time to live for givenkey
.Set the expiration for givenkey
as a date timestamp.Request information and statistics about connected clients.Returns the default serializer used by this template.Get the time to live forkey
in seconds.Get the time to live forkey
in and convert it to the givenTimeUnit
.Returns the hashKeySerializer.Returns the hashValueSerializer.Returns the key serializer used by this template.Returns the stringSerializer.Returns the value serializer used by this template.Determine if givenkey
exists.boolean
boolean
Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the default).Find all keys matching the givenpattern
.void
killClient
(String host, int port) Closes a given client connection identified by ip:port given inclient
.Move givenkey
to database withindex
.void
multi()
Mark the start of a transaction block.Returns the cluster specific operations interface.Returns geospatial specific operations interface.<HK,
HV> HashOperations<K, HK, HV> Returns the operations performed on hash values.Returns the operations performed on list values.Returns the operations performed on set values.<HK,
HV> StreamOperations<K, HK, HV> Returns the operations performed on Streams.<HK,
HV> StreamOperations<K, HK, HV> opsForStream
(HashMapper<? super K, ? super HK, ? super HV> hashMapper) Returns the operations performed on Streams.Returns the operations performed on simple values (or Strings in Redis terminology).Returns the operations performed on zset values (also known as sorted sets).Remove the expiration from givenkey
.protected <T> T
postProcessResult
(T result, RedisConnection conn, boolean existingConnection) protected RedisConnection
preProcessConnection
(RedisConnection connection, boolean existingConnection) Processes the connection (before any settings are executed on it).Return a random key from the keyspace.void
Rename keyoldKey
tonewKey
.renameIfAbsent
(K oldKey, K newKey) Rename keyoldKey
tonewKey
only ifnewKey
does not exist.void
Change redis replication setting to new master.void
Change server into master.void
Executes the Redis restore command.scan
(ScanOptions options) Use aCursor
to iterate over keys.void
setBeanClassLoader
(ClassLoader classLoader) Set theClassLoader
to be used for the defaultJdkSerializationRedisSerializer
in case no otherRedisSerializer
is explicitly set as the default one.void
setDefaultSerializer
(RedisSerializer<?> serializer) Sets the default serializer to use for this template.void
setEnableDefaultSerializer
(boolean enableDefaultSerializer) void
setEnableTransactionSupport
(boolean enableTransactionSupport) If set totrue
RedisTemplate
will participate in ongoing transactions using MULTI...EXEC|DISCARD to keep track of operations.void
setExposeConnection
(boolean exposeConnection) Sets whether to expose the Redis connection toRedisCallback
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
setScriptExecutor
(ScriptExecutor<K> scriptExecutor) 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.Sort the elements forquery
.Sort the elements forquery
and store result instoreKey
.<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) Sort the elements forquery
applyingBulkMapper
.<T> List<T>
sort
(SortQuery<K> query, RedisSerializer<T> resultSerializer) Sort the elements forquery
applyingRedisSerializer
.Determine the type stored atkey
.unlink
(Collection<K> keys) Unlink thekeys
from the keyspace.Unlink thekey
from the keyspace.void
unwatch()
Flushes all the previouslyRedisOperations.watch(Object)
keys.void
watch
(Collection<K> keys) Watch givenkeys
for modifications during transaction started withRedisOperations.multi()
.void
Watch givenkey
for modifications during transaction started withRedisOperations.multi()
.Methods inherited from class org.springframework.data.redis.core.RedisAccessor
getConnectionFactory, getRequiredConnectionFactory, setConnectionFactory
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.data.redis.core.RedisOperations
expire, expireAt, restore
-
Constructor Details
-
RedisTemplate
public RedisTemplate()Constructs a newRedisTemplate
instance.
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
- Overrides:
afterPropertiesSet
in classRedisAccessor
-
isExposeConnection
public boolean isExposeConnection()Returns whether to expose the native Redis connection to RedisCallback code, or rather a connection proxy (the default).- Returns:
- whether to expose the native Redis connection or not
-
setExposeConnection
public void setExposeConnection(boolean exposeConnection) Sets whether to expose the Redis connection toRedisCallback
code. Default is "false": a proxy will be returned, suppressingquit
anddisconnect
calls.- Parameters:
exposeConnection
-
-
isEnableDefaultSerializer
public boolean isEnableDefaultSerializer()- Returns:
- Whether or not the default serializer should be used. If not, any serializers not explicitly set will remain null and values will not be serialized or deserialized.
-
setEnableDefaultSerializer
public void setEnableDefaultSerializer(boolean enableDefaultSerializer) - Parameters:
enableDefaultSerializer
- Whether or not the default serializer should be used. If not, any serializers not explicitly set will remain null and values will not be serialized or deserialized.
-
setEnableTransactionSupport
public void setEnableTransactionSupport(boolean enableTransactionSupport) If set totrue
RedisTemplate
will participate in ongoing transactions using MULTI...EXEC|DISCARD to keep track of operations.- Parameters:
enableTransactionSupport
- whether to participate in ongoing transactions.- Since:
- 1.3
- See Also:
-
setBeanClassLoader
Set theClassLoader
to be used for the defaultJdkSerializationRedisSerializer
in case no otherRedisSerializer
is explicitly set as the default one.- Specified by:
setBeanClassLoader
in interfaceBeanClassLoaderAware
- Parameters:
classLoader
- can be null.- Since:
- 1.8
- See Also:
-
getDefaultSerializer
Returns the default serializer used by this template.- Returns:
- template default serializer
-
setDefaultSerializer
Sets the default serializer to use for this template. All serializers (except thesetStringSerializer(RedisSerializer)
) are initialized to this value unless explicitly set. Defaults toJdkSerializationRedisSerializer
.- Parameters:
serializer
- default serializer to use
-
setKeySerializer
Sets the key serializer to be used by this template. Defaults togetDefaultSerializer()
.- Parameters:
serializer
- the key serializer to be used by this template.
-
getKeySerializer
Returns the key serializer used by this template.- Specified by:
getKeySerializer
in interfaceRedisOperations<K,
V> - Returns:
- the key serializer used by this template.
-
setValueSerializer
Sets the value serializer to be used by this template. Defaults togetDefaultSerializer()
.- Parameters:
serializer
- the value serializer to be used by this template.
-
getValueSerializer
Returns the value serializer used by this template.- Specified by:
getValueSerializer
in interfaceRedisOperations<K,
V> - Returns:
- the value serializer used by this template.
-
getHashKeySerializer
Returns the hashKeySerializer.- Specified by:
getHashKeySerializer
in interfaceRedisOperations<K,
V> - Returns:
- Returns the hashKeySerializer
-
setHashKeySerializer
Sets the hash key (or field) serializer to be used by this template. Defaults togetDefaultSerializer()
.- Parameters:
hashKeySerializer
- The hashKeySerializer to set.
-
getHashValueSerializer
Returns the hashValueSerializer.- Specified by:
getHashValueSerializer
in interfaceRedisOperations<K,
V> - Returns:
- Returns the hashValueSerializer
-
setHashValueSerializer
Sets the hash value serializer to be used by this template. Defaults togetDefaultSerializer()
.- Parameters:
hashValueSerializer
- The hashValueSerializer to set.
-
getStringSerializer
Returns the stringSerializer.- Returns:
- Returns the stringSerializer
-
setStringSerializer
Sets the string value serializer to be used by this template (when the arguments or return types are always strings). Defaults toStringRedisSerializer
.- Parameters:
stringSerializer
- The stringValueSerializer to set.- See Also:
-
setScriptExecutor
- Parameters:
scriptExecutor
- TheScriptExecutor
to use for executing Redis scripts
-
execute
Description copied from interface:RedisOperations
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.- Specified by:
execute
in interfaceRedisOperations<K,
V> - Type Parameters:
T
- return type- Parameters:
action
- callback object that specifies the Redis action. Must not be null.- Returns:
- a result object returned by the action or null
-
execute
Executes the given action object within a connection, which can be exposed or not.- Type Parameters:
T
- return type- Parameters:
action
- callback object that specifies the Redis actionexposeConnection
- whether to enforce exposure of the native Redis Connection to callback code- Returns:
- object returned by the action
-
execute
Executes the given action object within a connection that can be exposed or not. Additionally, the connection can be pipelined. Note the results of the pipeline are discarded (making it suitable for write-only scenarios).- Type Parameters:
T
- return type- Parameters:
action
- 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- Returns:
- object returned by the action
-
execute
Description copied from interface:RedisOperations
Executes a Redis session. Allows multiple operations to be executed in the same session enabling 'transactional' capabilities throughRedisOperations.multi()
andRedisOperations.watch(Collection)
operations.- Specified by:
execute
in interfaceRedisOperations<K,
V> - Type Parameters:
T
- return type- Parameters:
session
- session callback. Must not be null.- Returns:
- result object returned by the action or null
-
executePipelined
Description copied from interface:RedisOperations
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.- Specified by:
executePipelined
in interfaceRedisOperations<K,
V> - Parameters:
session
- Session callback- Returns:
- list of objects returned by the pipeline
-
executePipelined
public List<Object> executePipelined(SessionCallback<?> session, @Nullable RedisSerializer<?> resultSerializer) Description copied from interface:RedisOperations
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.- Specified by:
executePipelined
in interfaceRedisOperations<K,
V> - Parameters:
session
- Session callback- Returns:
- list of objects returned by the pipeline
-
executePipelined
Description copied from interface:RedisOperations
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- Specified by:
executePipelined
in interfaceRedisOperations<K,
V> - Parameters:
action
- callback object to execute- Returns:
- list of objects returned by the pipeline
-
executePipelined
public List<Object> executePipelined(RedisCallback<?> action, @Nullable RedisSerializer<?> resultSerializer) Description copied from interface:RedisOperations
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.- Specified by:
executePipelined
in interfaceRedisOperations<K,
V> - Parameters:
action
- callback object to executeresultSerializer
- 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
-
execute
Description copied from interface:RedisOperations
Executes the givenRedisScript
- Specified by:
execute
in interfaceRedisOperations<K,
V> - Parameters:
script
- The script to executekeys
- Any keys that need to be passed to the scriptargs
- 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
public <T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args) Description copied from interface:RedisOperations
Executes the givenRedisScript
, using the providedRedisSerializer
s to serialize the script arguments and result.- Specified by:
execute
in interfaceRedisOperations<K,
V> - Parameters:
script
- The script to executeargsSerializer
- TheRedisSerializer
to use for serializing argsresultSerializer
- TheRedisSerializer
to use for serializing the script return valuekeys
- Any keys that need to be passed to the scriptargs
- 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")
-
executeWithStickyConnection
Description copied from interface:RedisOperations
Allocates and binds a newRedisConnection
to the actual return type of the method. It is up to the caller to free resources after use.- Specified by:
executeWithStickyConnection
in interfaceRedisOperations<K,
V> - Parameters:
callback
- must not be null.- Returns:
-
createRedisConnectionProxy
-
preProcessConnection
protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) Processes the connection (before any settings are executed on it). Default implementation returns the connection as is.- Parameters:
connection
- redis connection
-
postProcessResult
@Nullable protected <T> T postProcessResult(@Nullable T result, RedisConnection conn, boolean existingConnection) -
copy
Description copied from interface:RedisOperations
Copy givensourceKey
totargetKey
.- Specified by:
copy
in interfaceRedisOperations<K,
V> - Parameters:
source
- must not be null.target
- must not be null.replace
- whether the key was copied. null when used in pipeline / transaction.- Returns:
- See Also:
-
hasKey
Description copied from interface:RedisOperations
Determine if givenkey
exists.- Specified by:
hasKey
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- See Also:
-
countExistingKeys
Description copied from interface:RedisOperations
Count the number ofkeys
that exist.- Specified by:
countExistingKeys
in interfaceRedisOperations<K,
V> - Parameters:
keys
- must not be null.- Returns:
- The number of keys existing among the ones specified as arguments. Keys mentioned multiple times and existing are counted multiple times.
- See Also:
-
delete
Description copied from interface:RedisOperations
Delete givenkey
.- Specified by:
delete
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- true if the key was removed.
- See Also:
-
delete
Description copied from interface:RedisOperations
Delete givenkeys
.- Specified by:
delete
in interfaceRedisOperations<K,
V> - Parameters:
keys
- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- See Also:
-
unlink
Description copied from interface:RedisOperations
Unlink thekey
from the keyspace. Unlike withRedisOperations.delete(Object)
the actual memory reclaiming here happens asynchronously.- Specified by:
unlink
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- See Also:
-
unlink
Description copied from interface:RedisOperations
Unlink thekeys
from the keyspace. Unlike withRedisOperations.delete(Collection)
the actual memory reclaiming here happens asynchronously.- Specified by:
unlink
in interfaceRedisOperations<K,
V> - Parameters:
keys
- must not be null.- Returns:
- The number of keys that were removed. null when used in pipeline / transaction.
- See Also:
-
type
Description copied from interface:RedisOperations
Determine the type stored atkey
.- Specified by:
type
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
keys
Description copied from interface:RedisOperations
Find all keys matching the givenpattern
.- Specified by:
keys
in interfaceRedisOperations<K,
V> - Parameters:
pattern
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
scan
Description copied from interface:RedisOperations
Use aCursor
to iterate over keys.
Important: CallCloseableIterator.close()
when done to avoid resource leaks.- Specified by:
scan
in interfaceRedisOperations<K,
V> - Parameters:
options
- must not be null.- Returns:
- the result cursor providing access to the scan result. Must be closed once fully processed (e.g. through a try-with-resources clause).
- See Also:
-
randomKey
Description copied from interface:RedisOperations
Return a random key from the keyspace.- Specified by:
randomKey
in interfaceRedisOperations<K,
V> - Returns:
- null no keys exist or when used in pipeline / transaction.
- See Also:
-
rename
Description copied from interface:RedisOperations
Rename keyoldKey
tonewKey
.- Specified by:
rename
in interfaceRedisOperations<K,
V> - Parameters:
oldKey
- must not be null.newKey
- must not be null.- See Also:
-
renameIfAbsent
Description copied from interface:RedisOperations
Rename keyoldKey
tonewKey
only ifnewKey
does not exist.- Specified by:
renameIfAbsent
in interfaceRedisOperations<K,
V> - Parameters:
oldKey
- must not be null.newKey
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
expire
Description copied from interface:RedisOperations
Set time to live for givenkey
.- Specified by:
expire
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.unit
- must not be null.- Returns:
- null when used in pipeline / transaction.
-
expireAt
Description copied from interface:RedisOperations
Set the expiration for givenkey
as a date timestamp.- Specified by:
expireAt
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.date
- must not be null.- Returns:
- null when used in pipeline / transaction.
-
persist
Description copied from interface:RedisOperations
Remove the expiration from givenkey
.- Specified by:
persist
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
getExpire
Description copied from interface:RedisOperations
Get the time to live forkey
in seconds.- Specified by:
getExpire
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
getExpire
Description copied from interface:RedisOperations
Get the time to live forkey
in and convert it to the givenTimeUnit
.- Specified by:
getExpire
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.timeUnit
- must not be null.- Returns:
- null when used in pipeline / transaction.
-
move
Description copied from interface:RedisOperations
Move givenkey
to database withindex
.- Specified by:
move
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- null when used in pipeline / transaction.
- See Also:
-
dump
Executes the Redis dump command and returns the results. Redis uses a non-standard serialization mechanism and includes checksum information, thus the raw bytes are returned as opposed to deserializing with valueSerializer. Use the return value of dump as the value argument to restore- Specified by:
dump
in interfaceRedisOperations<K,
V> - Parameters:
key
- The key to dump- Returns:
- results The results of the dump operation
- See Also:
-
restore
Executes the Redis restore command. The value passed in should be the exact serialized data returned fromdump(Object)
, since Redis uses a non-standard serialization mechanism.- Specified by:
restore
in interfaceRedisOperations<K,
V> - Parameters:
key
- The key to restorevalue
- The value to restore, as returned bydump(Object)
timeToLive
- An expiration for the restored key, or 0 for no expirationunit
- The time unit for timeToLivereplace
- use true to replace a potentially existing value instead of erroring.- Throws:
RedisSystemException
- if the key you are attempting to restore already exists andreplace
is set to false.- See Also:
-
sort
Description copied from interface:RedisOperations
Sort the elements forquery
.- Specified by:
sort
in interfaceRedisOperations<K,
V> - Parameters:
query
- must not be null.- Returns:
- the results of sort. null when used in pipeline / transaction.
- See Also:
-
sort
Description copied from interface:RedisOperations
Sort the elements forquery
applyingRedisSerializer
.- Specified by:
sort
in interfaceRedisOperations<K,
V> - Parameters:
query
- must not be null.- Returns:
- the deserialized results of sort. null when used in pipeline / transaction.
- See Also:
-
sort
Description copied from interface:RedisOperations
Sort the elements forquery
applyingBulkMapper
.- Specified by:
sort
in interfaceRedisOperations<K,
V> - Parameters:
query
- must not be null.- Returns:
- the deserialized results of sort. null when used in pipeline / transaction.
- See Also:
-
sort
public <T,S> List<T> sort(SortQuery<K> query, BulkMapper<T, S> bulkMapper, @Nullable RedisSerializer<S> resultSerializer) Description copied from interface:RedisOperations
- Specified by:
sort
in interfaceRedisOperations<K,
V> - Parameters:
query
- must not be null.- Returns:
- the deserialized results of sort. null when used in pipeline / transaction.
- See Also:
-
sort
Description copied from interface:RedisOperations
Sort the elements forquery
and store result instoreKey
.- Specified by:
sort
in interfaceRedisOperations<K,
V> - Parameters:
query
- must not be null.storeKey
- must not be null.- Returns:
- number of values. null when used in pipeline / transaction.
- See Also:
-
watch
Description copied from interface:RedisOperations
Watch givenkey
for modifications during transaction started withRedisOperations.multi()
.- Specified by:
watch
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- See Also:
-
watch
Description copied from interface:RedisOperations
Watch givenkeys
for modifications during transaction started withRedisOperations.multi()
.- Specified by:
watch
in interfaceRedisOperations<K,
V> - Parameters:
keys
- must not be null.- See Also:
-
unwatch
public void unwatch()Description copied from interface:RedisOperations
Flushes all the previouslyRedisOperations.watch(Object)
keys.- Specified by:
unwatch
in interfaceRedisOperations<K,
V> - See Also:
-
multi
public void multi()Description copied from interface:RedisOperations
Mark the start of a transaction block.
Commands will be queued and can then be executed by callingRedisOperations.exec()
or rolled back usingRedisOperations.discard()
- Specified by:
multi
in interfaceRedisOperations<K,
V> - See Also:
-
discard
public void discard()Description copied from interface:RedisOperations
Discard all commands issued afterRedisOperations.multi()
.- Specified by:
discard
in interfaceRedisOperations<K,
V> - See Also:
-
exec
Execute a transaction, using the defaultRedisSerializer
s to deserialize any results that are byte[]s or Collections or Maps of byte[]s or Tuples. Other result types (Long, Boolean, etc) are left as-is in the converted results. If conversion of tx results has been disabled in theRedisConnectionFactory
, the results of exec will be returned without deserialization. This check is mostly for backwards compatibility with 1.0.- Specified by:
exec
in interfaceRedisOperations<K,
V> - Returns:
- The (possibly deserialized) results of transaction exec
- See Also:
-
exec
Description copied from interface:RedisOperations
Execute a transaction, using the providedRedisSerializer
to deserialize any results that are byte[]s or Collections of byte[]s. If a result is a Map, the providedRedisSerializer
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.- Specified by:
exec
in interfaceRedisOperations<K,
V> - Parameters:
valueSerializer
- TheRedisSerializer
to use for deserializing the results of transaction exec- Returns:
- The deserialized results of transaction exec
-
execRaw
-
getClientList
Description copied from interface:RedisOperations
Request information and statistics about connected clients.- Specified by:
getClientList
in interfaceRedisOperations<K,
V> - Returns:
List
ofRedisClientInfo
objects.
-
killClient
Description copied from interface:RedisOperations
Closes a given client connection identified by ip:port given inclient
.- Specified by:
killClient
in interfaceRedisOperations<K,
V> - Parameters:
host
- of connection to close.port
- of connection to close
-
replicaOf
Description copied from interface:RedisOperations
Change redis replication setting to new master.- Specified by:
replicaOf
in interfaceRedisOperations<K,
V> - Parameters:
host
- must not be null.- See Also:
-
replicaOfNoOne
public void replicaOfNoOne()Description copied from interface:RedisOperations
Change server into master.- Specified by:
replicaOfNoOne
in interfaceRedisOperations<K,
V> - See Also:
-
convertAndSend
Description copied from interface:RedisOperations
Publishes the given message to the given channel.- Specified by:
convertAndSend
in interfaceRedisOperations<K,
V> - Parameters:
channel
- the channel to publish to, must not be null.message
- message to publish.- Returns:
- the number of clients that received the message. null when used in pipeline / transaction.
- See Also:
-
opsForCluster
Description copied from interface:RedisOperations
Returns the cluster specific operations interface.- Specified by:
opsForCluster
in interfaceRedisOperations<K,
V> - Returns:
- never null.
-
opsForGeo
Description copied from interface:RedisOperations
Returns geospatial specific operations interface.- Specified by:
opsForGeo
in interfaceRedisOperations<K,
V> - Returns:
- never null.
-
boundGeoOps
Description copied from interface:RedisOperations
Returns geospatial specific operations interface bound to the given key.- Specified by:
boundGeoOps
in interfaceRedisOperations<K,
V> - Parameters:
key
- must not be null.- Returns:
- never null.
-
boundHashOps
Description copied from interface:RedisOperations
Returns the operations performed on hash values bound to the given key.- Specified by:
boundHashOps
in interfaceRedisOperations<K,
V> - Type Parameters:
HK
- hash key (or field) typeHV
- hash value type- Parameters:
key
- Redis key- Returns:
- hash operations bound to the given key.
-
opsForHash
Description copied from interface:RedisOperations
Returns the operations performed on hash values.- Specified by:
opsForHash
in interfaceRedisOperations<K,
V> - Type Parameters:
HK
- hash key (or field) typeHV
- hash value type- Returns:
- hash operations
-
opsForHyperLogLog
- Specified by:
opsForHyperLogLog
in interfaceRedisOperations<K,
V> - Returns:
-
opsForList
Description copied from interface:RedisOperations
Returns the operations performed on list values.- Specified by:
opsForList
in interfaceRedisOperations<K,
V> - Returns:
- list operations
-
boundListOps
Description copied from interface:RedisOperations
Returns the operations performed on list values bound to the given key.- Specified by:
boundListOps
in interfaceRedisOperations<K,
V> - Parameters:
key
- Redis key- Returns:
- list operations bound to the given key
-
boundSetOps
Description copied from interface:RedisOperations
Returns the operations performed on set values bound to the given key.- Specified by:
boundSetOps
in interfaceRedisOperations<K,
V> - Parameters:
key
- Redis key- Returns:
- set operations bound to the given key
-
opsForSet
Description copied from interface:RedisOperations
Returns the operations performed on set values.- Specified by:
opsForSet
in interfaceRedisOperations<K,
V> - Returns:
- set operations
-
opsForStream
Description copied from interface:RedisOperations
Returns the operations performed on Streams.- Specified by:
opsForStream
in interfaceRedisOperations<K,
V> - Returns:
- stream operations.
-
opsForStream
public <HK,HV> StreamOperations<K,HK, opsForStreamHV> (HashMapper<? super K, ? super HK, ? super HV> hashMapper) Description copied from interface:RedisOperations
Returns the operations performed on Streams.- Specified by:
opsForStream
in interfaceRedisOperations<K,
V> - Parameters:
hashMapper
- theHashMapper
to use when convertingObjectRecord
.- Returns:
- stream operations.
-
boundStreamOps
Description copied from interface:RedisOperations
Returns the operations performed on Streams bound to the given key.- Specified by:
boundStreamOps
in interfaceRedisOperations<K,
V> - Returns:
- stream operations.
-
boundValueOps
Description copied from interface:RedisOperations
Returns the operations performed on simple values (or Strings in Redis terminology) bound to the given key.- Specified by:
boundValueOps
in interfaceRedisOperations<K,
V> - Parameters:
key
- Redis key- Returns:
- value operations bound to the given key
-
opsForValue
Description copied from interface:RedisOperations
Returns the operations performed on simple values (or Strings in Redis terminology).- Specified by:
opsForValue
in interfaceRedisOperations<K,
V> - Returns:
- value operations
-
boundZSetOps
Description copied from interface:RedisOperations
Returns the operations performed on zset values (also known as sorted sets) bound to the given key.- Specified by:
boundZSetOps
in interfaceRedisOperations<K,
V> - Parameters:
key
- Redis key- Returns:
- zset operations bound to the given key.
-
opsForZSet
Description copied from interface:RedisOperations
Returns the operations performed on zset values (also known as sorted sets).- Specified by:
opsForZSet
in interfaceRedisOperations<K,
V> - Returns:
- zset operations
-