public interface RedisOperations<K,V>
RedisTemplate. Not often used but a
useful option for extensibility and testability (as it can be easily mocked or stubbed).| Modifier and Type | Method and Description |
|---|---|
BoundGeoOperations<K,V> |
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. * @param
|
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.
|
<HK,HV> BoundStreamOperations<K,HK,HV> |
boundStreamOps(K key)
Returns the operations performed on Streams 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)
Publishes the given message to the given channel.
|
Long |
countExistingKeys(Collection<K> keys)
Count the number of
keys that exist. |
Long |
delete(Collection<K> keys)
Delete given
keys. |
Boolean |
delete(K key)
Delete given
key. |
void |
discard()
Discard all commands issued after
multi(). |
byte[] |
dump(K key)
Retrieve serialized version of the value stored at
key. |
List<Object> |
exec()
Executes all queued commands in a transaction started with
multi(). |
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.
|
<T extends Closeable> |
executeWithStickyConnection(RedisCallback<T> callback)
Allocates and binds a new
RedisConnection to the actual return type of the method. |
default Boolean |
expire(K key,
Duration timeout)
Set time to live for given
key. |
Boolean |
expire(K key,
long timeout,
TimeUnit unit)
Set time to live for given
key. |
Boolean |
expireAt(K key,
Date date)
Set the expiration for given
key as a date timestamp. |
default Boolean |
expireAt(K key,
Instant expireAt)
Set the expiration for given
key as a date timestamp. |
List<RedisClientInfo> |
getClientList()
Request information and statistics about connected clients.
|
Long |
getExpire(K key)
Get the time to live for
key in seconds. |
Long |
getExpire(K key,
TimeUnit timeUnit)
Get the time to live for
key in and convert it to the given TimeUnit. |
RedisSerializer<?> |
getHashKeySerializer() |
RedisSerializer<?> |
getHashValueSerializer() |
RedisSerializer<?> |
getKeySerializer() |
RedisSerializer<?> |
getValueSerializer() |
Boolean |
hasKey(K key)
Determine if given
key exists. |
Set<K> |
keys(K pattern)
Find all keys matching the given
pattern. |
void |
killClient(String host,
int port)
Closes a given client connection identified by ip:port given in
client. |
Boolean |
move(K key,
int dbIndex)
Move given
key to database with index. |
void |
multi()
Mark the start of a transaction block.
|
ClusterOperations<K,V> |
opsForCluster()
Returns the cluster specific operations interface.
|
GeoOperations<K,V> |
opsForGeo()
Returns geospatial specific operations interface.
|
<HK,HV> HashOperations<K,HK,HV> |
opsForHash()
Returns the operations performed on hash values.
|
HyperLogLogOperations<K,V> |
opsForHyperLogLog() |
ListOperations<K,V> |
opsForList()
Returns the operations performed on list values.
|
SetOperations<K,V> |
opsForSet()
Returns the operations performed on set values.
|
<HK,HV> StreamOperations<K,HK,HV> |
opsForStream()
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.
|
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)
Remove the expiration from given
key. |
K |
randomKey()
Return a random key from the keyspace.
|
void |
rename(K oldKey,
K newKey)
Rename key
oldKey to newKey. |
Boolean |
renameIfAbsent(K oldKey,
K newKey)
Rename key
oldKey to newKey only if newKey does not exist. |
default void |
restore(K key,
byte[] value,
long timeToLive,
TimeUnit unit)
|
void |
restore(K key,
byte[] value,
long timeToLive,
TimeUnit unit,
boolean replace)
|
void |
slaveOf(String host,
int port)
Change redis replication setting to new master.
|
void |
slaveOfNoOne()
Change server into master.
|
List<V> |
sort(SortQuery<K> query)
Sort the elements for
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)
Sort the elements for
query applying BulkMapper. |
Long |
sort(SortQuery<K> query,
K storeKey)
Sort the elements for
query and store result in storeKey. |
<T> List<T> |
sort(SortQuery<K> query,
RedisSerializer<T> resultSerializer)
Sort the elements for
query applying RedisSerializer. |
DataType |
type(K key)
Determine the type stored at
key. |
Long |
unlink(Collection<K> keys)
Unlink the
keys from the keyspace. |
Boolean |
unlink(K key)
Unlink the
key from the keyspace. |
void |
unwatch()
Flushes all the previously
watch(Object) keys. |
void |
watch(Collection<K> keys)
Watch given
keys for modifications during transaction started with multi(). |
void |
watch(K key)
Watch given
key for modifications during transaction started with multi(). |
@Nullable <T> T execute(RedisCallback<T> action)
T - return typeaction - callback object that specifies the Redis action. Must not be null.@Nullable <T> T execute(SessionCallback<T> session)
multi() and watch(Collection) operations.T - return typesession - session callback. Must not be null.List<Object> executePipelined(RedisCallback<?> action)
action - callback object to executeList<Object> executePipelined(RedisCallback<?> action, RedisSerializer<?> resultSerializer)
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 valueList<Object> executePipelined(SessionCallback<?> session)
session - Session callbackList<Object> executePipelined(SessionCallback<?> session, RedisSerializer<?> resultSerializer)
session - Session callbackresultSerializer - @Nullable <T> T execute(RedisScript<T> script, List<K> keys, Object... args)
RedisScriptscript - The script to executekeys - Any keys that need to be passed to the scriptargs - Any args that need to be passed to the scriptRedisScript.getResultType() is null, likely indicating a
throw-away status reply (i.e. "OK")@Nullable <T> T execute(RedisScript<T> script, RedisSerializer<?> argsSerializer, RedisSerializer<T> resultSerializer, List<K> keys, Object... args)
RedisScript, using the provided RedisSerializers to serialize the script
arguments and result.script - The script to executeargsSerializer - The RedisSerializer to use for serializing argsresultSerializer - The RedisSerializer 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 scriptRedisScript.getResultType() is null, likely indicating a
throw-away status reply (i.e. "OK")@Nullable <T extends Closeable> T executeWithStickyConnection(RedisCallback<T> callback)
RedisConnection to the actual return type of the method. It is up to the caller
to free resources after use.callback - must not be null.@Nullable Boolean hasKey(K key)
key exists.key - must not be null.@Nullable Long countExistingKeys(Collection<K> keys)
keys that exist.keys - must not be null.@Nullable Boolean delete(K key)
key.key - must not be null.@Nullable Long delete(Collection<K> keys)
keys.keys - must not be null.@Nullable Boolean unlink(K key)
key from the keyspace. Unlike with delete(Object) the actual memory reclaiming here
happens asynchronously.key - must not be null.@Nullable Long unlink(Collection<K> keys)
keys from the keyspace. Unlike with delete(Collection) the actual memory reclaiming
here happens asynchronously.keys - must not be null.@Nullable DataType type(K key)
key.key - must not be null.@Nullable Set<K> keys(K pattern)
pattern.pattern - must not be null.@Nullable K randomKey()
void rename(K oldKey, K newKey)
oldKey to newKey.oldKey - must not be null.newKey - must not be null.@Nullable Boolean renameIfAbsent(K oldKey, K newKey)
oldKey to newKey only if newKey does not exist.oldKey - must not be null.newKey - must not be null.@Nullable Boolean expire(K key, long timeout, TimeUnit unit)
key.key - must not be null.timeout - unit - must not be null.@Nullable default Boolean expire(K key, Duration timeout)
key.key - must not be null.timeout - must not be null.IllegalArgumentException - if the timeout is null.@Nullable Boolean expireAt(K key, Date date)
key as a date timestamp.key - must not be null.date - must not be null.@Nullable default Boolean expireAt(K key, Instant expireAt)
key as a date timestamp.key - must not be null.expireAt - must not be null.IllegalArgumentException - if the instant is null or too large to represent as a Date.@Nullable Boolean persist(K key)
key.key - must not be null.@Nullable Boolean move(K key, int dbIndex)
key to database with index.key - must not be null.dbIndex - @Nullable byte[] dump(K key)
key.key - must not be null.default void restore(K key, byte[] value, long timeToLive, TimeUnit unit)
key - must not be null.value - must not be null.timeToLive - unit - must not be null.void restore(K key, byte[] value, long timeToLive, TimeUnit unit, boolean replace)
key - must not be null.value - must not be null.timeToLive - unit - must not be null.replace - use true to replace a potentially existing value instead of erroring.@Nullable Long getExpire(K key)
key in seconds.key - must not be null.@Nullable Long getExpire(K key, TimeUnit timeUnit)
key in and convert it to the given TimeUnit.key - must not be null.timeUnit - must not be null.@Nullable List<V> sort(SortQuery<K> query)
query.query - must not be null.@Nullable <T> List<T> sort(SortQuery<K> query, RedisSerializer<T> resultSerializer)
query applying RedisSerializer.query - must not be null.@Nullable <T> List<T> sort(SortQuery<K> query, BulkMapper<T,V> bulkMapper)
query applying BulkMapper.query - must not be null.@Nullable <T,S> List<T> sort(SortQuery<K> query, BulkMapper<T,S> bulkMapper, RedisSerializer<S> resultSerializer)
query - must not be null.@Nullable Long sort(SortQuery<K> query, K storeKey)
query and store result in storeKey.query - must not be null.storeKey - must not be null.void watch(K key)
key for modifications during transaction started with multi().key - must not be null.void watch(Collection<K> keys)
keys for modifications during transaction started with multi().keys - must not be null.void unwatch()
watch(Object) keys.void multi()
exec() or rolled back using discard()
void discard()
multi().List<Object> exec()
multi(). watch(Object) the operation will fail if any of watched keys has been modified.List<Object> exec(RedisSerializer<?> valueSerializer)
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.valueSerializer - The RedisSerializer to use for deserializing the results of transaction exec@Nullable List<RedisClientInfo> getClientList()
List of RedisClientInfo objects.void killClient(String host, int port)
client.host - of connection to close.port - of connection to closevoid slaveOf(String host, int port)
host - must not be null.port - void slaveOfNoOne()
void convertAndSend(String destination, Object message)
destination - the channel to publish to, must not be null.message - message to publishClusterOperations<K,V> opsForCluster()
GeoOperations<K,V> opsForGeo()
BoundGeoOperations<K,V> boundGeoOps(K key)
key - must not be null.<HK,HV> HashOperations<K,HK,HV> opsForHash()
HK - hash key (or field) typeHV - hash value type<HK,HV> BoundHashOperations<K,HK,HV> boundHashOps(K key)
HV - hash value typekey - Redis keyHyperLogLogOperations<K,V> opsForHyperLogLog()
ListOperations<K,V> opsForList()
BoundListOperations<K,V> boundListOps(K key)
key - Redis keySetOperations<K,V> opsForSet()
BoundSetOperations<K,V> boundSetOps(K key)
key - Redis key<HK,HV> StreamOperations<K,HK,HV> opsForStream()
<HK,HV> StreamOperations<K,HK,HV> opsForStream(HashMapper<? super K,? super HK,? super HV> hashMapper)
hashMapper - the HashMapper to use when converting ObjectRecord.<HK,HV> BoundStreamOperations<K,HK,HV> boundStreamOps(K key)
ValueOperations<K,V> opsForValue()
BoundValueOperations<K,V> boundValueOps(K key)
key - Redis keyZSetOperations<K,V> opsForZSet()
BoundZSetOperations<K,V> boundZSetOps(K key)
key - Redis keyRedisSerializer<?> getKeySerializer()
RedisSerializer.RedisSerializer<?> getValueSerializer()
RedisSerializer.RedisSerializer<?> getHashKeySerializer()
RedisSerializer.RedisSerializer<?> getHashValueSerializer()
RedisSerializer.Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.