Class RedisAPI
java.lang.Object
net.swofty.redisapi.api.RedisAPI
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic RedisAPIgenerateInstance(@NonNull String uri) Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generationstatic RedisAPIgenerateInstance(@NonNull String uri, String password) Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generationstatic RedisAPIgenerateInstance(@NonNull RedisCredentials credentials) Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generationpublishMessage(String filterId, RedisChannel channel, String message) Asynchronously publishes a message to the generated instances redis poolpublishMessage(RedisChannel channel, String message) Asynchronously publishes a message to the generated instances redis poolregisterChannel(String channelName, @NonNull Class<? extends RedisMessagingReceiveInterface> receiveEventClass) Used to register a redis channel, this must be done before sending any messages on this channelregisterChannel(String channelName, @NonNull Consumer<RedisMessagingReceiveEvent> receiveEventConsumer) Used to register a redis channel, this must be done before sending any messages on this channelvoidshutdown()Stops the Pub/Sub listener thread (if running), closes the pool, and shuts down the worker pools.voidStarts listeners for the Redis Pub/Sub channels.
-
Constructor Details
-
RedisAPI
public RedisAPI()
-
-
Method Details
-
generateInstance
Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generation- Parameters:
credentials- the credentials used to connect to the Redis server running, instanceof api.RedisCredentials- Returns:
- main instance of the api.RedisAPI
- Throws:
CouldNotConnectToRedisException- signifies either an issue with the password passed through or the URI that is passed through the method
-
generateInstance
Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generation- Parameters:
uri- the URI used to connect to the Redis server running (e.g. redis://username:password@localhost:6379 or redis://localhost:6379)- Returns:
- main instance of the api.RedisAPI
- Throws:
CouldNotConnectToRedisException- signifies either an issue with the password passed through or the URI that is passed through the method
-
generateInstance
Creates a new main Redis pool instance, there will only ever be one at a time so #getInstance should be used after generation- Parameters:
uri- the URI used to connect to the Redis server running (e.g. redis://localhost:6379)password- the password used to connect to the Redis server running- Returns:
- main instance of the api.RedisAPI
- Throws:
CouldNotConnectToRedisException- signifies either an issue with the password passed through or the URI that is passed through the method
-
startListeners
public void startListeners()Starts listeners for the Redis Pub/Sub channels. This creates a single long-lived subscriber connection. -
shutdown
public void shutdown()Stops the Pub/Sub listener thread (if running), closes the pool, and shuts down the worker pools. Work already queued on the workers is allowed to finish. -
publishMessage
Asynchronously publishes a message to the generated instances redis pool- Parameters:
channel- the channel object being published to, this is what should be registered on your other instancesmessage- the message being sent across that channel- Returns:
- a
CompletableFuture<Void>representing the asynchronous operation
-
publishMessage
public CompletableFuture<Void> publishMessage(String filterId, RedisChannel channel, String message) Asynchronously publishes a message to the generated instances redis pool- Parameters:
filterId- the filter id for the message being sent, this filter id is checked by all the receiving pools to ensure that only a specific Jedis pool handles the messagechannel- the channel object being published to, this is what should be registered on your other instancesmessage- the message being sent across that channel- Returns:
- a
CompletableFuture<Void>representing the asynchronous operation
-
registerChannel
public RedisChannel registerChannel(String channelName, @NonNull @NonNull Class<? extends RedisMessagingReceiveInterface> receiveEventClass) Used to register a redis channel, this must be done before sending any messages on this channel- Parameters:
channelName- the name of the channel, this is what is used when publishing a messagereceiveEventClass- the class which extends RedisMessagingReceiveInterface, this is where incoming messages on this channel will be sent- Returns:
- object of the registered RedisChannel
- Throws:
ChannelAlreadyRegisteredException- exception is thrown if channel with same name is already registered
-
registerChannel
public RedisChannel registerChannel(String channelName, @NonNull @NonNull Consumer<RedisMessagingReceiveEvent> receiveEventConsumer) Used to register a redis channel, this must be done before sending any messages on this channel- Parameters:
channelName- the name of the channel, this is what is used when publishing a messagereceiveEventConsumer- the consumer which has RedisMessagingReceiveEvent, this is where incoming messages on this channel will be sent- Returns:
- object of the registered RedisChannel
- Throws:
ChannelAlreadyRegisteredException- exception is thrown if channel with same name is already registered
-