public class RedisCache<K,V> extends java.lang.Object implements CacheWithLifetimes<K,V>
Constructor and Description |
---|
RedisCache(redis.clients.jedis.Jedis jedisCache,
long defaultLifespan)
Constructor in which already-created Jedis instance is passed in to be used as underlying
cache.
|
RedisCache(java.lang.String host,
int port,
int timeout,
long defaultLifespan)
Create a cache with the specified lifetime connected to Redis at the specified host &
port.
|
RedisCache(java.lang.String host,
int port,
long defaultLifespan)
Create a cache with the specified lifetime connected to Redis at the specified host &
port.
|
RedisCache(java.lang.String host,
long defaultLifespan)
Create a cache with the specified lifetime connected to Redis at the specified host.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Delete all entries from the cache.
|
void |
close()
Close the Redis connection.
|
void |
delete(K key)
Delete a key-value pair from the cache.
|
void |
deleteAll(java.util.List<K> keys)
Delete one or more key-value pairs from the cache.
|
java.lang.String |
flushAll()
Delete all key-value pairs from all databases
|
V |
get(K key)
Look up a value in the cache.
|
java.util.Map<K,V> |
getAll(java.util.List<K> keys)
Look up one or more values in the cache.
|
CacheEntry<V> |
getCacheEntry(K key)
Look up a CacheEntry in the cache.
|
RedisCacheStats |
getStatistics()
Get cache statistics.
|
java.lang.String |
printCacheEntry(K key)
Return string representing a cache entry corresponding to a key (or indicate if the
key is not in the cache).
|
void |
put(K key,
V value)
Cache a key-value pair.
|
void |
put(K key,
V value,
long lifetime)
Cache a key-value pair.
|
void |
putAll(java.util.Map<K,V> map)
Cache one or more key-value pairs.
|
void |
putAll(java.util.Map<K,V> map,
long lifetime)
Cache one or more key-value pairs.
|
long |
size() |
java.lang.String |
toString()
Output contents of current database to a string.
|
public RedisCache(java.lang.String host, long defaultLifespan)
host
- host where Redis is runningdefaultLifespan
- default life time in milliseconds for cached objectspublic RedisCache(java.lang.String host, int port, long defaultLifespan)
host
- host where Redis is runningport
- port numberdefaultLifespan
- default life time in milliseconds for cached objectspublic RedisCache(java.lang.String host, int port, int timeout, long defaultLifespan)
Configure Jedis to close idle connections after the specified time.
host
- host where Redis is runningport
- port numbertimeout
- number of seconds before Jedis closes an idle connectiondefaultLifespan
- default life time in milliseconds for cached objectspublic RedisCache(redis.clients.jedis.Jedis jedisCache, long defaultLifespan)
jedisCache
- Existing Jedis instance to be used as underlying cachedefaultLifespan
- Default life time in milliseconds for cached objectspublic void clear()
public void close()
public void delete(K key)
public void deleteAll(java.util.List<K> keys)
public java.lang.String flushAll()
public java.util.Map<K,V> getAll(java.util.List<K> keys)
public CacheEntry<V> getCacheEntry(K key)
getCacheEntry
in interface CacheWithLifetimes<K,V>
key
- key corresponding to valuenull
if key is not
in cachepublic RedisCacheStats getStatistics()
For Redis, cache statistics are contained in a string. The string is
returned by RedisCacheStats.getStats()
.
getStatistics
in interface Cache<K,V>
public java.lang.String printCacheEntry(K key)
key
- key corresponding to valuepublic void put(K key, V value, long lifetime)
put
in interface CacheWithLifetimes<K,V>
key
- key associated with valuevalue
- value associated with keylifetime
- lifetime in milliseconds associated with datapublic void putAll(java.util.Map<K,V> map, long lifetime)
putAll
in interface CacheWithLifetimes<K,V>
map
- map containing key-value pairs to cachelifetime
- lifetime in milliseconds associated with each key-value pair.
If the system supports revalidation of expired cache entries to determine if
expired entries are really obsolete, a value <= 0
indicates cached
entry should always be revalidated before being returned to clientpublic long size()
public java.lang.String toString()
toString
in class java.lang.Object