Package dev.voidframework.redis.impl
Class DefaultRedis
java.lang.Object
dev.voidframework.redis.impl.DefaultRedis
- All Implemented Interfaces:
Redis
Implementation of
Redis.-
Constructor Summary
ConstructorsConstructorDescriptionDefaultRedis(com.google.inject.Provider<redis.clients.jedis.Jedis> jedisProvider, com.typesafe.config.Config configuration) Build a new instance. -
Method Summary
Modifier and TypeMethodDescription<T> longAdds a value in a list.<T> longaddInList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value, int maxItem) Adds a value in a list.longAdds a value in a list.longAdds a value in a list.<T> longAdds a value in a list.<T> longAdds a value in a list.longDecrements a number value.longDecrements a number value.booleanChecks if key is present on Redis database.<T> TRetrieves an object by key.<T> TRetrieves an object by key.<T> TRetrieves an object by key.redis.clients.jedis.JedisGets a Redis connection from the pool.redis.clients.jedis.JedisgetConnection(int db) Gets a Redis connection from the pool pre-configured with the right database.<T> List<T>getFromList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Gets values from a list.<T> List<T>getFromList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, int offset, int count) Gets values from a list.<T> List<T>getFromList(String key, com.fasterxml.jackson.databind.JavaType javaType) Gets values from a list.<T> List<T>getFromList(String key, com.fasterxml.jackson.databind.JavaType javaType, int offset, int count) Gets values from a list.<T> List<T>getFromList(String key, Class<T> clazz) Gets values from a list.<T> List<T>getFromList(String key, Class<T> clazz, int offset, int count) Gets values from a list.<T> TgetOrElse(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Callable<T> block) Retrieves a value from the cache, or set it from a default Callable function.<T> TgetOrElse(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Callable<T> block, int expiration) Retrieves a value from the cache, or set it from a default Callable function.<T> TRetrieves a value from the cache, or set it from a default Callable function.<T> TgetOrElse(String key, com.fasterxml.jackson.databind.JavaType javaType, Callable<T> block, int expiration) Retrieves a value from the cache, or set it from a default Callable function.<T> TRetrieves a value from the cache, or set it from a default Callable function.<T> TRetrieves a value from the cache, or set it from a default Callable function.longIncrements an integer value.longIncrements a number value.voidRemoves a value from the cache.voidRemoves a value from the cache.<T> voidSets a value without expiration.<T> voidset(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, T value, int expiration) Sets a value with expiration.voidSets a value without expiration.voidSets a value with expiration.<T> voidSets a value without expiration.<T> voidSets a value with expiration.booleanTries to acquire a lock.
-
Constructor Details
-
DefaultRedis
@Inject public DefaultRedis(com.google.inject.Provider<redis.clients.jedis.Jedis> jedisProvider, com.typesafe.config.Config configuration) Build a new instance.- Parameters:
jedisProvider- The Jedis resource providerconfiguration- The application configuration
-
-
Method Details
-
getConnection
public redis.clients.jedis.Jedis getConnection()Description copied from interface:RedisGets a Redis connection from the pool.- Specified by:
getConnectionin interfaceRedis- Returns:
- A Redis connection
-
getConnection
public redis.clients.jedis.Jedis getConnection(int db) Description copied from interface:RedisGets a Redis connection from the pool pre-configured with the right database. If the database number is under zero, the database "zero" will be selected.- Specified by:
getConnectionin interfaceRedis- Parameters:
db- The database number to use- Returns:
- A Redis connection
-
get
Description copied from interface:RedisRetrieves an object by key. -
get
Description copied from interface:RedisRetrieves an object by key. -
get
Description copied from interface:RedisRetrieves an object by key. -
set
public <T> void set(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, T value) Description copied from interface:RedisSets a value without expiration. -
set
public <T> void set(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, T value, int expiration) Description copied from interface:RedisSets a value with expiration. -
set
Description copied from interface:RedisSets a value without expiration. -
set
Description copied from interface:RedisSets a value with expiration. -
set
Description copied from interface:RedisSets a value without expiration. -
set
public void set(String key, com.fasterxml.jackson.databind.JavaType javaType, Object value, int expiration) Description copied from interface:RedisSets a value with expiration. -
getOrElse
public <T> T getOrElse(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Callable<T> block) Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function. The value has no expiration. -
getOrElse
public <T> T getOrElse(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Callable<T> block, int expiration) Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function.- Specified by:
getOrElsein interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- Item keytypeReference- The object type referenceblock- block returning value to set if key does not existexpiration- expiration period in seconds- Returns:
- value
-
getOrElse
Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function. The value has no expiration. -
getOrElse
Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function. -
getOrElse
public <T> T getOrElse(String key, com.fasterxml.jackson.databind.JavaType javaType, Callable<T> block) Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function. The value has no expiration. -
getOrElse
public <T> T getOrElse(String key, com.fasterxml.jackson.databind.JavaType javaType, Callable<T> block, int expiration) Description copied from interface:RedisRetrieves a value from the cache, or set it from a default Callable function. -
remove
Description copied from interface:RedisRemoves a value from the cache. -
remove
Description copied from interface:RedisRemoves a value from the cache. -
exists
Description copied from interface:RedisChecks if key is present on Redis database. -
addInList
public <T> long addInList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value) Description copied from interface:RedisAdds a value in a list. -
addInList
public <T> long addInList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value, int maxItem) Description copied from interface:RedisAdds a value in a list.- Specified by:
addInListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keytypeReference- The object type referencevalue- The value to add in the listmaxItem- The number of entries to keep in list- Returns:
- The list size
-
addInList
Description copied from interface:RedisAdds a value in a list. -
addInList
Description copied from interface:RedisAdds a value in a list. -
addInList
Description copied from interface:RedisAdds a value in a list. -
addInList
public long addInList(String key, com.fasterxml.jackson.databind.JavaType javaType, Object value, int maxItem) Description copied from interface:RedisAdds a value in a list. -
getFromList
public <T> List<T> getFromList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keytypeReference- The object type reference- Returns:
- The values list
-
getFromList
public <T> List<T> getFromList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, int offset, int count) Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keytypeReference- The object type referenceoffset- From wherecount- The number of items to retrieve- Returns:
- The values list
-
getFromList
Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keyclazz- The object class- Returns:
- The values list
-
getFromList
Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keyclazz- The object classoffset- From wherecount- The number of items to retrieve- Returns:
- The values list
-
getFromList
Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keyjavaType- The object java type- Returns:
- The values list
-
getFromList
public <T> List<T> getFromList(String key, com.fasterxml.jackson.databind.JavaType javaType, int offset, int count) Description copied from interface:RedisGets values from a list.- Specified by:
getFromListin interfaceRedis- Type Parameters:
T- Generic type of something implementingjava.io.Serializable- Parameters:
key- The list keyjavaType- The object java typeoffset- From wherecount- The number of items to retrieve- Returns:
- The values list
-
tryLock
Description copied from interface:RedisTries to acquire a lock. This method will returnfalseif it can't acquire lock or can't connect to Redis server. -
decrement
Description copied from interface:RedisDecrements a number value. If key does not exist, it will be created automatically. Expiration is set only when the key is created. -
decrement
Description copied from interface:RedisDecrements a number value. If key does not exists, it will be created automatically. -
increment
Description copied from interface:RedisIncrements an integer value. If key does not exists, it will be created automatically. -
increment
Description copied from interface:RedisIncrements a number value. If key does not exist, it will be created automatically. Expiration is set only when the key is created.
-