Package overit.geocall.cache
Interface RedisDB
public interface RedisDB
Connector for communications to and from the redis server
-
Method Summary
Modifier and TypeMethodDescriptionvoidbroadcast(overit.geocall.cluster.redis.Message msg, boolean meToo) Sends a broadcast message to all listeners who have registered on the current channel.voidFast way to delete a single key from redis.voidremoves all records whose key matches the pattern passed as input<T> TCreates a newJedisconnection and pass it as argument to the function parameter that can execute the commands to the redis server.Fast way to get a single string from redis.booleanisReady()Check if the Redis service is available and runningExtracts a set of keys from the redis server.normalizeKey(String key) Normalize the given key by appending a prefix based on the deployment ID.voidRecords a listener on receipt of a message from the redis server.voidonReconnect(Runnable listener) Records a listener on the reconnection event to the redis server.voidFast way to set a new string inside redis.voidstop()Close the communication with the redis server.voidunwatch()Method used to unsubscribe the previous subscription (if any)voidMethod used to subscribe to the reception of notifications from a certain channel.
-
Method Details
-
normalizeKey
Normalize the given key by appending a prefix based on the deployment ID. If the deployment ID is not available, the prefix "unknown" will be used. The normalized key will have the format "{prefix}:{key}".- Parameters:
key- the key to be normalized- Returns:
- the normalized key
-
stop
void stop()Close the communication with the redis server. After the invocation of this method, no mere connections can be extracted. -
watch
Method used to subscribe to the reception of notifications from a certain channel. The sequent subscription will have no effect; you have to call theunwatch()method before subscribe again to a new channel- Parameters:
channel- name of the channel to subscribe to
-
unwatch
void unwatch()Method used to unsubscribe the previous subscription (if any) -
onReconnect
Records a listener on the reconnection event to the redis server. Thewatch(String)must be called before the registration, otherwise no notification will be received.- Parameters:
listener- instance of the listener that will be called on every reconnection.
-
onMessage
Records a listener on receipt of a message from the redis server. Thewatch(String)must be called before the registration, otherwise no notification will be received.- Parameters:
listener- instance of the listener that will be called on every message.
-
execute
Creates a newJedisconnection and pass it as argument to the function parameter that can execute the commands to the redis server. After the function has been called, the connection will be closed.- Type Parameters:
T- the function return type- Parameters:
function- the function that will be called once the connection has been created- Returns:
- the function execution result
-
keys
Extracts a set of keys from the redis server. The result set contains only the keys that respect a specific pattern- Parameters:
pattern- see MATCH option in the Redis documentationtype- see TYPE option in the Redis documentation- Returns:
- a set of the extracted key of an empty set if there's none that matches with the pattern
- Throws:
RedisDBException- in case of any error during the key extraction
-
del
removes all records whose key matches the pattern passed as input- Parameters:
pattern- see MATCH option in the Redis documentationtype- see TYPE option in the Redis documentation- Throws:
RedisDBException- in case of any error during the removal
-
broadcast
Sends a broadcast message to all listeners who have registered on the current channel. Thewatch(String)must be called before use this method.- Parameters:
msg- the message that will be sendmeToo-truedi the notification must be received by the listeners registered to this connector,falseotherwise- Throws:
IllegalStateException- if you have not subscribed to any channelRedisDBException- in case of any error during the sending
-
set
Fast way to set a new string inside redis. This method is intended for a simple use case that doesn't require to pipeline commands, or set additional parameters like NX, EX ... . To support complex use cases, use theexecute(Function)method.- Parameters:
key- the reference keyvalue- the value that will be set
-
get
Fast way to get a single string from redis. This method is intended for a simple use case that doesn't require to pipeline commands. To support complex use cases, use theexecute(Function)method.- Parameters:
key- the reference key- Returns:
- the key value or
nullif the key doesn't exist
-
del
Fast way to delete a single key from redis. This method is intended for a simple use case that doesn't require to pipeline commands. To support complex use cases, use theexecute(Function)method.- Parameters:
key- the reference key
-
isReady
boolean isReady()Check if the Redis service is available and running- Returns:
trueif Redis is up and running;falseotherwise
-