Class RedisClient

java.lang.Object
net.bitbylogic.rps.client.RedisClient

public class RedisClient extends Object
  • Constructor Details

    • RedisClient

      public RedisClient(@NotNull @NotNull RedisManager redisManager, @NotNull @NotNull String clientId)
      Constructs a new RedisClient instance with the specified RedisManager and client ID. Initializes the client with the server ID retrieved from the RedisManager and registers the request topic for message handling.
      Parameters:
      redisManager - The RedisManager instance responsible for managing Redis operations. Must not be null.
      clientId - The unique identifier for this RedisClient instance. Must not be null.
  • Method Details

    • registerListener

      public void registerListener(@NotNull @NotNull RedisMessageListener listener)
      Registers a Redis message listener with the client. This method ensures that the provided listener is not already registered. If the listener is being registered for the first time, it is added to the internal list of listeners, associated with the current client instance, and the listener's subscription channel is registered for incoming messages.
      Parameters:
      listener - The Redis message listener to register. Must not be null.
    • sendListenerMessage

      public void sendListenerMessage(@NotNull @NotNull ListenerComponent component)
      Sends a listener message to a Redis topic and handles timed requests associated with the message. This method binds the provided ListenerComponent to the current RedisClient instance as its source, processes any timed requests defined in the component, and publishes the message to a Redis topic. Debug information can also be logged if enabled in the RedisManager.
      Parameters:
      component - The ListenerComponent to be sent. Must not be null. The component encapsulates channel, target server, data, and potentially timed requests.
    • sendTimedResponse

      public void sendTimedResponse(@NotNull @NotNull ListenerComponent component)
      Sends a timed response message using the specified ListenerComponent. This method binds the provided ListenerComponent to the current RedisClient instance as its source, verifies that at least one timed response is defined in the component, and then publishes the component as a message to a Redis topic. If debug mode is enabled in the RedisManager, debug information about the operation is logged.
      Parameters:
      component - The ListenerComponent containing the timed responses to be sent. Must not be null
    • getRedisClient

      public org.redisson.api.RedissonClient getRedisClient()
      Retrieves the Redisson client instance used to interact with Redis.

      This method provides access to the underlying RedissonClient which enables operations such as data storage, messaging, and synchronization across Redis.

      Returns:
      the RedissonClient instance managed by the redisManager.