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> long
Adds a value in a list.<T> long
addInList
(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value, int maxItem) Adds a value in a list.long
Adds a value in a list.long
Adds a value in a list.<T> long
Adds a value in a list.<T> long
Adds a value in a list.long
Decrements a number value.long
Decrements a number value.boolean
Checks if key is present on Redis database.<T> T
Retrieves an object by key.<T> T
Retrieves an object by key.<T> T
Retrieves an object by key.redis.clients.jedis.Jedis
Gets a Redis connection from the pool.redis.clients.jedis.Jedis
getConnection
(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> T
getOrElse
(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> T
getOrElse
(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> T
Retrieves a value from the cache, or set it from a default Callable function.<T> T
getOrElse
(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> T
Retrieves a value from the cache, or set it from a default Callable function.<T> T
Retrieves a value from the cache, or set it from a default Callable function.long
Increments an integer value.long
Increments a number value.void
Removes a value from the cache.void
Removes a value from the cache.<T> void
Sets a value without expiration.<T> void
set
(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, T value, int expiration) Sets a value with expiration.void
Sets a value without expiration.void
Sets a value with expiration.<T> void
Sets a value without expiration.<T> void
Sets a value with expiration.boolean
Tries 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:Redis
Gets a Redis connection from the pool.- Specified by:
getConnection
in interfaceRedis
- Returns:
- A Redis connection
-
getConnection
public redis.clients.jedis.Jedis getConnection(int db) Description copied from interface:Redis
Gets 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:
getConnection
in interfaceRedis
- Parameters:
db
- The database number to use- Returns:
- A Redis connection
-
get
Description copied from interface:Redis
Retrieves an object by key. -
get
Description copied from interface:Redis
Retrieves an object by key. -
get
Description copied from interface:Redis
Retrieves 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:Redis
Sets 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:Redis
Sets a value with expiration. -
set
Description copied from interface:Redis
Sets a value without expiration. -
set
Description copied from interface:Redis
Sets a value with expiration. -
set
Description copied from interface:Redis
Sets a value without expiration. -
set
public void set(String key, com.fasterxml.jackson.databind.JavaType javaType, Object value, int expiration) Description copied from interface:Redis
Sets 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:Redis
Retrieves 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:Redis
Retrieves a value from the cache, or set it from a default Callable function.- Specified by:
getOrElse
in 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:Redis
Retrieves a value from the cache, or set it from a default Callable function. The value has no expiration. -
getOrElse
Description copied from interface:Redis
Retrieves 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:Redis
Retrieves 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:Redis
Retrieves a value from the cache, or set it from a default Callable function. -
remove
Description copied from interface:Redis
Removes a value from the cache. -
remove
Description copied from interface:Redis
Removes a value from the cache. -
exists
Description copied from interface:Redis
Checks 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:Redis
Adds 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:Redis
Adds a value in a list.- Specified by:
addInList
in 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:Redis
Adds a value in a list. -
addInList
Description copied from interface:Redis
Adds a value in a list. -
addInList
Description copied from interface:Redis
Adds 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:Redis
Adds 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Gets values from a list.- Specified by:
getFromList
in 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:Redis
Tries to acquire a lock. This method will returnfalse
if it can't acquire lock or can't connect to Redis server. -
decrement
Description copied from interface:Redis
Decrements 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:Redis
Decrements a number value. If key does not exists, it will be created automatically. -
increment
Description copied from interface:Redis
Increments an integer value. If key does not exists, it will be created automatically. -
increment
Description copied from interface:Redis
Increments a number value. If key does not exist, it will be created automatically. Expiration is set only when the key is created.
-