Class RedisHandler
java.lang.Object
id.luckynetwork.lyrams.lyralibs.core.database.redis.RedisHandler
-
Constructor Summary
ConstructorsConstructorDescriptionRedisHandler(Returnable<ExecutorService> executorServiceReturnable, Logger logger, RedisConfiguration redisConfiguration) -
Method Summary
Modifier and TypeMethodDescriptionvoidbroadcastObject(Object object) This function sends an object to all connected clientsvoidclose()> Close the redis clientbooleanconnect()We create three JedisPools, one for each of the Jedis instances we'll be using, and then we ping each of them to make sure they're working.booleanIf any of the three pools are not connected, or if the pubSub is not subscribed, then return false.It tries to reconnect to the redis servervoidregisterListener(Object clazz) It loops through all the methods in the class, and if it finds a method with the RedisListener annotation, it checks if the method has one parameter, and if it does, it adds the method to the dataMapvoidregisterObject(Class<?> clazz) If the class has the RedisObject annotation, add it to the objectMapvoidsendObject(Object object, @NotNull String targetServer) It sends an object to a specific server
-
Constructor Details
-
RedisHandler
public RedisHandler(Returnable<ExecutorService> executorServiceReturnable, Logger logger, RedisConfiguration redisConfiguration) throws Exception - Throws:
Exception
-
-
Method Details
-
connect
public boolean connect()We create three JedisPools, one for each of the Jedis instances we'll be using, and then we ping each of them to make sure they're working.- Returns:
- A boolean value.
-
isConnected
public boolean isConnected()If any of the three pools are not connected, or if the pubSub is not subscribed, then return false.- Returns:
- A boolean value.
-
reconnect
It tries to reconnect to the redis server- Returns:
- A CompletableFuture that will run the reconnection process.
-
registerObject
If the class has the RedisObject annotation, add it to the objectMap- Parameters:
clazz- The class that is being registered.
-
registerListener
It loops through all the methods in the class, and if it finds a method with the RedisListener annotation, it checks if the method has one parameter, and if it does, it adds the method to the dataMap- Parameters:
clazz- The class that contains the method that will be called when a packet is received.
-
broadcastObject
This function sends an object to all connected clients- Parameters:
object- The object to send.
-
sendObject
It sends an object to a specific server- Parameters:
object- The object to sendtargetServer- The server to send the object to.
-
close
public void close()> Close the redis client
-