Class Redis

java.lang.Object
dev.demeng.pluginbase.redis.Redis
All Implemented Interfaces:
IRedis, dev.demeng.pluginbase.terminable.Terminable, AutoCloseable

public class Redis extends Object implements IRedis
  • Field Summary

    Fields inherited from interface dev.demeng.pluginbase.terminable.Terminable

    EMPTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Redis(@NotNull String serverId, @NotNull RedisCredentials credentials, @NotNull String... channels)
    Creates a new Redis manager.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the Redis connection and unsubscribes to all channels.
    boolean
    Returns whether the channel is subscribed to or not.
    boolean
    publishObject(@NotNull String channel, @NotNull Object obj)
    Publishes the object to the provided channel.
    boolean
    publishString(@NotNull String channel, @NotNull String str)
    Publishes the object to the provided channel.
    boolean
    subscribe(@NotNull String... channels)
    Subscribes to the provided channels if they have not been subcribed to already.
    void
    unsubscribe(@NotNull String... channels)
    Unsubscribes from the given channels.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface dev.demeng.pluginbase.redis.IRedis

    getJedisPool

    Methods inherited from interface dev.demeng.pluginbase.terminable.Terminable

    bindWith, closeAndReportException, closeSilently, isClosed
  • Constructor Details

    • Redis

      public Redis(@NotNull @NotNull String serverId, @NotNull @NotNull RedisCredentials credentials, @NotNull @NotNull String... channels)
      Creates a new Redis manager.
      Parameters:
      serverId - Server's unique identifier
      credentials - Redis server credentials
      channels - Channels to immediately subscribe to
  • Method Details

    • subscribe

      public boolean subscribe(@NotNull @NotNull String... channels)
      Subscribes to the provided channels if they have not been subcribed to already.
      Parameters:
      channels - Names of the channels to subscribe
      Returns:
      If at least 1 channel has been subcribed to
    • unsubscribe

      public void unsubscribe(@NotNull @NotNull String... channels)
      Unsubscribes from the given channels.
      Parameters:
      channels - Names of the channels to unsubscribe
    • publishObject

      public boolean publishObject(@NotNull @NotNull String channel, @NotNull @NotNull Object obj)
      Publishes the object to the provided channel. For simple strings, use publishString(String, String) instead.
      Parameters:
      channel - Channel to be published into
      obj - Object to be published
      Returns:
      True if successful, false if in closing state or failed to serialize
    • publishString

      public boolean publishString(@NotNull @NotNull String channel, @NotNull @NotNull String str)
      Publishes the object to the provided channel. To publish objects, use publishObject(String, Object) instead.
      Parameters:
      channel - Channel to be published into
      str - String to be published
      Returns:
      True if successful, false if in closing state or failed to serialize
    • close

      public void close()
      Closes the Redis connection and unsubscribes to all channels.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface dev.demeng.pluginbase.terminable.Terminable
    • isSubscribed

      public boolean isSubscribed(String channel)
      Returns whether the channel is subscribed to or not.
      Parameters:
      channel - The channel to check
      Returns:
      If the channel is subscribed to or not