Package net.carcdr.yhocuspocus.redis
Interface RedisClient
- All Superinterfaces:
AutoCloseable
- All Known Implementing Classes:
LettuceRedisClient
Abstract interface for Redis operations used by the Redis extension.
This interface abstracts the underlying Redis client library (Lettuce, Jedis, etc.) to allow different implementations and easier testing.
Implementations must be thread-safe.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the client and releases resources.Deletes a key.CompletableFuture<byte[]> Gets a binary value by key.booleanChecks if the client is connected.Publishes a message to a channel.Sets a binary value by key.subscribe(String channel, BiConsumer<String, byte[]> handler) Subscribes to a channel.unsubscribe(String channel) Unsubscribes from a channel.
-
Method Details
-
publish
Publishes a message to a channel.- Parameters:
channel- the channel to publish tomessage- the message bytes- Returns:
- a future that completes when the message is sent
-
subscribe
Subscribes to a channel.- Parameters:
channel- the channel to subscribe tohandler- callback for received messages (channel, message)- Returns:
- a future that completes when subscribed
-
unsubscribe
Unsubscribes from a channel.- Parameters:
channel- the channel to unsubscribe from- Returns:
- a future that completes when unsubscribed
-
get
Gets a binary value by key.- Parameters:
key- the key- Returns:
- a future containing the value, or null if not found
-
set
Sets a binary value by key.- Parameters:
key- the keyvalue- the value- Returns:
- a future that completes when set
-
delete
Deletes a key.- Parameters:
key- the key to delete- Returns:
- a future that completes when deleted
-
isConnected
boolean isConnected()Checks if the client is connected.- Returns:
- true if connected
-
close
void close()Closes the client and releases resources.- Specified by:
closein interfaceAutoCloseable
-