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.
-
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.
-
Method Details
-
getConnection
redis.clients.jedis.Jedis getConnection()Gets a Redis connection from the pool.- Returns:
- A Redis connection
-
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
-
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
-
get
Retrieves an object by key.- Type Parameters:
T- Generic type of something- Parameters:
key- Item keyclazz- The object class- Returns:
- object or
null
-
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
-
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
-
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
-
set
Sets a value without expiration.- Type Parameters:
T- Generic type of something- Parameters:
key- Item keyclazz- The object classvalue- The value to set
-
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
-
set
Sets a value without expiration.- Parameters:
key- Item keyjavaType- The object java typevalue- The value to set
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
remove
Removes a value from the cache.- Parameters:
key- The key to remove the value for
-
remove
Removes a value from the cache.- Parameters:
keys- Keys to remove from redis
-
exists
Checks if key is present on Redis database.- Parameters:
key- The key to test- Returns:
trueif the key is present on Redis database
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
tryLock
Tries to acquire a lock. This method will returnfalseif it can't acquire lock or can't connect to Redis server.- Parameters:
key- The lock keyexpiration- The lock TTL- Returns:
truein case of success, otherwise,false
-
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
-
decrement
Decrements a number value. If key does not exists, it will be created automatically.- Parameters:
key- The value key- Returns:
- The decremented value
-
increment
Increments an integer value. If key does not exists, it will be created automatically.- Parameters:
key- The value key- Returns:
- The incremented value
-
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
-