Interface RedisCacheWriter
- All Superinterfaces:
CacheStatisticsProvider
RedisCacheWriter provides low level access to Redis commands (SET, SETNX, GET, EXPIRE,...) used for
caching. The
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.
- Since:
- 2.0
- Author:
- Christoph Strobl, Mark Paluch
-
Method Summary
Modifier and TypeMethodDescriptionvoidRemove all keys following the given pattern.voidclearStatistics(String name) Reset all statistics counters and gauges for this cache.byte[]Get the binary value representation from Redis stored for the given key.static RedisCacheWriterlockingRedisCacheWriter(RedisConnectionFactory connectionFactory) Create newRedisCacheWriterwith locking behavior.static RedisCacheWriterlockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy) Create newRedisCacheWriterwith locking behavior.static RedisCacheWriternonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory) Create newRedisCacheWriterwithout locking behavior.static RedisCacheWriternonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy) Create newRedisCacheWriterwithout locking behavior.voidWrite 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.voidRemove the given key from Redis.withStatisticsCollector(CacheStatisticsCollector cacheStatisticsCollector) Obtain aRedisCacheWriterusing the givenCacheStatisticsCollectorto collect metrics.Methods inherited from interface org.springframework.data.redis.cache.CacheStatisticsProvider
getCacheStatistics
-
Method Details
-
nonLockingRedisCacheWriter
Create newRedisCacheWriterwithout locking behavior.- Parameters:
connectionFactory- must not be null.- Returns:
- new instance of
DefaultRedisCacheWriter.
-
nonLockingRedisCacheWriter
static RedisCacheWriter nonLockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy) Create newRedisCacheWriterwithout locking behavior.- Parameters:
connectionFactory- must not be null.batchStrategy- must not be null.- Returns:
- new instance of
DefaultRedisCacheWriter. - Since:
- 2.6
-
lockingRedisCacheWriter
Create newRedisCacheWriterwith locking behavior.- Parameters:
connectionFactory- must not be null.- Returns:
- new instance of
DefaultRedisCacheWriter.
-
lockingRedisCacheWriter
static RedisCacheWriter lockingRedisCacheWriter(RedisConnectionFactory connectionFactory, BatchStrategy batchStrategy) Create newRedisCacheWriterwith locking behavior.- Parameters:
connectionFactory- must not be null.batchStrategy- must not be null.- Returns:
- new instance of
DefaultRedisCacheWriter. - Since:
- 2.6
-
put
Write the given key/value pair to Redis an set the expiration time if defined.- Parameters:
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.
-
get
Get the binary value representation from Redis stored for the given key.- Parameters:
name- must not be null.key- must not be null.- Returns:
- null if key does not exist.
-
putIfAbsent
Write the given value to Redis if the key does not already exist.- Parameters:
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.- Returns:
- null if the value has been written, the value stored for the key if it already exists.
-
remove
Remove the given key from Redis.- Parameters:
name- The cache name must not be null.key- The key for the cache entry. Must not be null.
-
clean
Remove all keys following the given pattern.- Parameters:
name- The cache name must not be null.pattern- The pattern for the keys to remove. Must not be null.
-
clearStatistics
Reset all statistics counters and gauges for this cache.- Since:
- 2.4
-
withStatisticsCollector
Obtain aRedisCacheWriterusing the givenCacheStatisticsCollectorto collect metrics.- Parameters:
cacheStatisticsCollector- must not be null.- Returns:
- new instance of
RedisCacheWriter.
-