Package dev.demeng.pluginbase.redis
Class Redis
java.lang.Object
dev.demeng.pluginbase.redis.Redis
- All Implemented Interfaces:
IRedis,dev.demeng.pluginbase.terminable.Terminable,AutoCloseable
-
Field Summary
Fields inherited from interface dev.demeng.pluginbase.terminable.Terminable
EMPTY -
Constructor Summary
ConstructorsConstructorDescriptionRedis(@NotNull String serverId, @NotNull RedisCredentials credentials, @NotNull String... channels) Creates a new Redis manager. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the Redis connection and unsubscribes to all channels.booleanisSubscribed(String channel) Returns whether the channel is subscribed to or not.booleanpublishObject(@NotNull String channel, @NotNull Object obj) Publishes the object to the provided channel.booleanpublishString(@NotNull String channel, @NotNull String str) Publishes the object to the provided channel.booleanSubscribes to the provided channels if they have not been subcribed to already.voidunsubscribe(@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, waitMethods inherited from interface dev.demeng.pluginbase.redis.IRedis
getJedisPoolMethods 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 identifiercredentials- Redis server credentialschannels- Channels to immediately subscribe to
-
-
Method Details
-
subscribe
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
Unsubscribes from the given channels.- Parameters:
channels- Names of the channels to unsubscribe
-
publishObject
Publishes the object to the provided channel. For simple strings, usepublishString(String, String)instead.- Parameters:
channel- Channel to be published intoobj- Object to be published- Returns:
- True if successful, false if in closing state or failed to serialize
-
publishString
Publishes the object to the provided channel. To publish objects, usepublishObject(String, Object)instead.- Parameters:
channel- Channel to be published intostr- 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:
closein interfaceAutoCloseable- Specified by:
closein interfacedev.demeng.pluginbase.terminable.Terminable
-
isSubscribed
Returns whether the channel is subscribed to or not.- Parameters:
channel- The channel to check- Returns:
- If the channel is subscribed to or not
-