Package net.carcdr.yhocuspocus.redis
Class LettuceRedisClient
java.lang.Object
net.carcdr.yhocuspocus.redis.LettuceRedisClient
- All Implemented Interfaces:
AutoCloseable,RedisClient
Redis client implementation using Lettuce.
Uses binary codec for values to support Y-CRDT state storage.
-
Constructor Summary
ConstructorsConstructorDescriptionLettuceRedisClient(io.lettuce.core.RedisClient lettuceClient) Creates a new Lettuce-based Redis client from an existing Lettuce client.LettuceRedisClient(io.lettuce.core.RedisURI uri) Creates a new Lettuce-based Redis client.LettuceRedisClient(String host, int port) Creates a new Lettuce-based Redis client. -
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.
-
Constructor Details
-
LettuceRedisClient
Creates a new Lettuce-based Redis client.- Parameters:
host- Redis hostport- Redis port
-
LettuceRedisClient
public LettuceRedisClient(io.lettuce.core.RedisURI uri) Creates a new Lettuce-based Redis client.- Parameters:
uri- Redis URI
-
LettuceRedisClient
public LettuceRedisClient(io.lettuce.core.RedisClient lettuceClient) Creates a new Lettuce-based Redis client from an existing Lettuce client.This constructor is useful for Spring integration where the client is already configured.
- Parameters:
lettuceClient- the existing Lettuce client
-
-
Method Details
-
publish
Description copied from interface:RedisClientPublishes a message to a channel.- Specified by:
publishin interfaceRedisClient- Parameters:
channel- the channel to publish tomessage- the message bytes- Returns:
- a future that completes when the message is sent
-
subscribe
Description copied from interface:RedisClientSubscribes to a channel.- Specified by:
subscribein interfaceRedisClient- Parameters:
channel- the channel to subscribe tohandler- callback for received messages (channel, message)- Returns:
- a future that completes when subscribed
-
unsubscribe
Description copied from interface:RedisClientUnsubscribes from a channel.- Specified by:
unsubscribein interfaceRedisClient- Parameters:
channel- the channel to unsubscribe from- Returns:
- a future that completes when unsubscribed
-
get
Description copied from interface:RedisClientGets a binary value by key.- Specified by:
getin interfaceRedisClient- Parameters:
key- the key- Returns:
- a future containing the value, or null if not found
-
set
Description copied from interface:RedisClientSets a binary value by key.- Specified by:
setin interfaceRedisClient- Parameters:
key- the keyvalue- the value- Returns:
- a future that completes when set
-
delete
Description copied from interface:RedisClientDeletes a key.- Specified by:
deletein interfaceRedisClient- Parameters:
key- the key to delete- Returns:
- a future that completes when deleted
-
isConnected
public boolean isConnected()Description copied from interface:RedisClientChecks if the client is connected.- Specified by:
isConnectedin interfaceRedisClient- Returns:
- true if connected
-
close
public void close()Description copied from interface:RedisClientCloses the client and releases resources.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceRedisClient
-