Package dev.voidframework.redis
Interface Redis
- All Known Implementing Classes:
DefaultRedis
public interface Redis
Redis service give access to methods to easily use a Redis database.
- Since:
- 1.1.0
-
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.
-
Method Details
-
getConnection
redis.clients.jedis.Jedis getConnection()Gets a Redis connection from the pool.- Returns:
- A Redis connection
- Since:
- 1.1.0
-
getConnection
redis.clients.jedis.Jedis getConnection(int db) 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.- Parameters:
db
- The database number to use- Returns:
- A Redis connection
- Since:
- 1.1.0
-
get
Retrieves an object by key.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keytypeReference
- The object type reference- Returns:
- object or
null
- Since:
- 1.1.0
-
get
Retrieves an object by key.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyclazz
- The object class- Returns:
- object or
null
- Since:
- 1.1.0
-
get
Retrieves an object by key.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyjavaType
- The object java type- Returns:
- object or
null
- Since:
- 1.1.0
-
set
Sets a value without expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keytypeReference
- The object type referencevalue
- The value to set- Since:
- 1.1.0
-
set
<T> void set(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, T value, int expiration) Sets a value with expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keytypeReference
- The object type referencevalue
- The value to setexpiration
- expiration in seconds- Since:
- 1.1.0
-
set
Sets a value without expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyclazz
- The object classvalue
- The value to set- Since:
- 1.1.0
-
set
Sets a value with expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyclazz
- The object classvalue
- The value to setexpiration
- expiration in seconds- Since:
- 1.1.0
-
set
Sets a value without expiration.- Parameters:
key
- Item keyjavaType
- The object java typevalue
- The value to set- Since:
- 1.1.0
-
set
void set(String key, com.fasterxml.jackson.databind.JavaType javaType, Object value, int expiration) Sets a value with expiration.- Parameters:
key
- Item keyjavaType
- The object java typevalue
- The value to setexpiration
- expiration in seconds- Since:
- 1.1.0
-
getOrElse
<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. The value has no expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keytypeReference
- The object type referenceblock
- block returning value to set if key does not exist- Returns:
- value
- Since:
- 1.1.0
-
getOrElse
<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.- 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
- Since:
- 1.1.0
-
getOrElse
Retrieves a value from the cache, or set it from a default Callable function. The value has no expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyclazz
- The object classblock
- block returning value to set if key does not exist- Returns:
- value
- Since:
- 1.1.0
-
getOrElse
Retrieves a value from the cache, or set it from a default Callable function.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- Item keyclazz
- The object classblock
- block returning value to set if key does not existexpiration
- expiration period in seconds- Returns:
- value
- Since:
- 1.1.0
-
getOrElse
Retrieves a value from the cache, or set it from a default Callable function. The value has no expiration.- Type Parameters:
T
- Generic type of something- Parameters:
key
- Item keyjavaType
- The object java typeblock
- block returning value to set if key does not exist- Returns:
- value
- Since:
- 1.1.0
-
getOrElse
<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.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- Item keyjavaType
- The object java typeblock
- block returning value to set if key does not existexpiration
- expiration period in seconds- Returns:
- value
- Since:
- 1.1.0
-
remove
Removes a value from the cache.- Parameters:
key
- The key to remove the value for- Since:
- 1.1.0
-
remove
Removes a value from the cache.- Parameters:
keys
- Keys to remove from redis- Since:
- 1.1.0
-
exists
Checks if key is present on Redis database.- Parameters:
key
- The key to test- Returns:
true
if the key is present on Redis database- Since:
- 1.1.0
-
addInList
<T> long addInList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value) Adds a value in a list.- 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 list- Returns:
- The list size
- Since:
- 1.1.0
-
addInList
<T> long addInList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, Object value, int maxItem) Adds a value in a list.- 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
- Since:
- 1.1.0
-
addInList
Adds a value in a list.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- The list keyclazz
- The object classvalue
- The value to add in the list- Returns:
- The list size
- Since:
- 1.1.0
-
addInList
Adds a value in a list.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- The list keyclazz
- The object classvalue
- The value to add in the listmaxItem
- The number of entries to keep in list- Returns:
- The list size
- Since:
- 1.1.0
-
addInList
Adds a value in a list.- Parameters:
key
- The list keyjavaType
- The object java typevalue
- The value to add in the list- Returns:
- The list size
- Since:
- 1.1.0
-
addInList
long addInList(String key, com.fasterxml.jackson.databind.JavaType javaType, Object value, int maxItem) Adds a value in a list.- Parameters:
key
- The list keyjavaType
- The object java typevalue
- The value to add in the listmaxItem
- The number of entries to keep in list- Returns:
- The list size
- Since:
- 1.1.0
-
getFromList
Gets values from a list.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- The list keytypeReference
- The object type reference- Returns:
- The values list
- Since:
- 1.1.0
-
getFromList
<T> List<T> getFromList(String key, com.fasterxml.jackson.core.type.TypeReference<T> typeReference, int offset, int count) Gets values from a list.- 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
- Since:
- 1.1.0
-
getFromList
Gets values from a list.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- The list keyclazz
- The object class- Returns:
- The values list
- Since:
- 1.1.0
-
getFromList
Gets values from a list.- 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
- Since:
- 1.1.0
-
getFromList
Gets values from a list.- Type Parameters:
T
- Generic type of something implementingjava.io.Serializable
- Parameters:
key
- The list keyjavaType
- The object java type- Returns:
- The values list
- Since:
- 1.1.0
-
getFromList
<T> List<T> getFromList(String key, com.fasterxml.jackson.databind.JavaType javaType, int offset, int count) Gets values from a list.- 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
- Since:
- 1.1.0
-
tryLock
Tries to acquire a lock. This method will returnfalse
if it can't acquire lock or can't connect to Redis server.- Parameters:
key
- The lock keyexpiration
- The lock TTL- Returns:
true
in case of success, otherwise,false
- Since:
- 1.1.0
-
decrement
Decrements a number value. If key does not exist, it will be created automatically. Expiration is set only when the key is created.- Parameters:
key
- The value keyexpiration
- The value TTL- Returns:
- The decremented value
- Since:
- 1.1.0
-
decrement
Decrements a number value. If key does not exist, it will be created automatically.- Parameters:
key
- The value key- Returns:
- The decremented value
- Since:
- 1.1.0
-
increment
Increments an integer value. If key does not exist, it will be created automatically.- Parameters:
key
- The value key- Returns:
- The incremented value
- Since:
- 1.1.0
-
increment
Increments a number value. If key does not exist, it will be created automatically. Expiration is set only when the key is created.- Parameters:
key
- The value keyexpiration
- The value TTL- Returns:
- The incremented value
- Since:
- 1.1.0
-