public interface RedisCacheWriter extends CacheStatisticsProvider
RedisCacheWriter
provides low level access to Redis commands (SET, SETNX, GET, EXPIRE,...
) used for
caching. RedisCacheWriter
may be shared by multiple cache implementations and is responsible for writing / reading
binary data to / from Redis. The implementation honors potential cache lock flags that might be set.
The default RedisCacheWriter
implementation can be customized with BatchStrategy
to tune performance
behavior.
Modifier and Type | Method and Description |
---|---|
void |
clean(String name,
byte[] pattern)
Remove all keys following the given pattern.
|
void |
clearStatistics(String name)
Reset all statistics counters and gauges for this cache.
|
byte[] |
get(String name,
byte[] key)
Get the binary value representation from Redis stored for the given key.
|
static RedisCacheWriter |
lockingRedisCacheWriter(RedisConnectionFactory connectionFactory)
Create new
RedisCacheWriter with locking behavior. |
static RedisCacheWriter |
lockingRedisCacheWriter(RedisConnectionFactory connectionFactory,
BatchStrategy batchStrategy)
Create new
RedisCacheWriter with locking behavior. |
static RedisCacheWriter |
nonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory)
Create new
RedisCacheWriter without locking behavior. |
static RedisCacheWriter |
nonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory,
BatchStrategy batchStrategy)
Create new
RedisCacheWriter without locking behavior. |
void |
put(String name,
byte[] key,
byte[] value,
Duration ttl)
Write the given key/value pair to Redis an set the expiration time if defined.
|
byte[] |
putIfAbsent(String name,
byte[] key,
byte[] value,
Duration ttl)
Write the given value to Redis if the key does not already exist.
|
void |
remove(String name,
byte[] key)
Remove the given key from Redis.
|
RedisCacheWriter |
withStatisticsCollector(CacheStatisticsCollector cacheStatisticsCollector)
Obtain a
RedisCacheWriter using the given CacheStatisticsCollector to collect metrics. |
getCacheStatistics
static RedisCacheWriter nonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory)
RedisCacheWriter
without locking behavior.connectionFactory
- must not be null.DefaultRedisCacheWriter
.static RedisCacheWriter nonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy)
RedisCacheWriter
without locking behavior.connectionFactory
- must not be null.batchStrategy
- must not be null.DefaultRedisCacheWriter
.static RedisCacheWriter lockingRedisCacheWriter(RedisConnectionFactory connectionFactory)
RedisCacheWriter
with locking behavior.connectionFactory
- must not be null.DefaultRedisCacheWriter
.static RedisCacheWriter lockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy)
RedisCacheWriter
with locking behavior.connectionFactory
- must not be null.batchStrategy
- must not be null.DefaultRedisCacheWriter
.void put(String name, byte[] key, byte[] value, @Nullable Duration ttl)
name
- The cache name must not be null.key
- The key for the cache entry. Must not be null.value
- The value stored for the key. Must not be null.ttl
- Optional expiration time. Can be null.@Nullable byte[] get(String name, byte[] key)
name
- must not be null.key
- must not be null.@Nullable byte[] putIfAbsent(String name, byte[] key, byte[] value, @Nullable Duration ttl)
name
- The cache name must not be null.key
- The key for the cache entry. Must not be null.value
- The value stored for the key. Must not be null.ttl
- Optional expiration time. Can be null.void remove(String name, byte[] key)
name
- The cache name must not be null.key
- The key for the cache entry. Must not be null.void clean(String name, byte[] pattern)
name
- The cache name must not be null.pattern
- The pattern for the keys to remove. Must not be null.void clearStatistics(String name)
RedisCacheWriter withStatisticsCollector(CacheStatisticsCollector cacheStatisticsCollector)
RedisCacheWriter
using the given CacheStatisticsCollector
to collect metrics.cacheStatisticsCollector
- must not be null.RedisCacheWriter
.Copyright © 2011–2023 Pivotal Software, Inc.. All rights reserved.