Class RedissonClientAdapter
java.lang.Object
io.agentscope.extensions.redis.state.redisson.RedissonClientAdapter
- All Implemented Interfaces:
RedisClientAdapter
Adapter for Redisson Redis client.
Redisson provides a comprehensive Redis client that automatically handles different deployment
modes through a unified RedissonClient interface.
This adapter supports all Redisson deployment modes:
- Standalone mode - single Redis instance
- Cluster mode - Redis Cluster with multiple nodes
- Sentinel mode - Redis with Sentinel for high availability
- Master/Slave mode - Redis with master-slave replication
RedissonClient manages connection pooling, thread safety, and mode-specific logic internally, providing a seamless experience across all deployment modes.
Usage Examples:
Standalone Mode:
// Create standalone configuration
Config config = new Config();
config.useSingleServer()
.setAddress("redis://localhost:6379")
.setConnectionMinimumIdleSize(5)
.setConnectionPoolSize(20);
// Create RedissonClient
RedissonClient redissonClient = Redisson.create(config);
// Create adapter
RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
// Use with RedisAgentStateStore
AgentStateStore stateStore = RedisAgentStateStore.builder()
.redissonClient(redissonClient)
.build();
Cluster Mode:
// Create cluster configuration
Config config = new Config();
config.useClusterServers()
.addNodeAddress("redis://localhost:7000", "redis://localhost:7001", "redis://localhost:7002")
.setScanInterval(2000);
// Create RedissonClient
RedissonClient redissonClient = Redisson.create(config);
// Create adapter
RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
Sentinel Mode:
// Create sentinel configuration
Config config = new Config();
config.useSentinelServers()
.setMasterName("mymaster")
.addSentinelAddress("redis://localhost:26379", "redis://localhost:26380")
.setDatabase(0);
// Create RedissonClient
RedissonClient redissonClient = Redisson.create(config);
// Create adapter
RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
Master/Slave Mode:
// Create master/slave configuration
Config config = new Config();
config.useMasterSlaveServers()
.setMasterAddress("redis://localhost:6379")
.addSlaveAddress("redis://localhost:6380", "redis://localhost:6381")
.setReadMode(ReadMode.SLAVE);
// Create RedissonClient
RedissonClient redissonClient = Redisson.create(config);
// Create adapter
RedissonClientAdapter adapter = RedissonClientAdapter.of(redissonClient);
-
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a member to a set.voidclose()Close the adapter and release resources.voiddeleteKeys(String... keys) Delete one or more keys.longExecute a Lua script atomically.findKeysByPattern(String pattern) Find all keys matching a pattern.Get a string value.longgetListLength(String key) Get the length of a list.getSetMembers(String key) Get all members of a set.longgetSetSize(String key) Get the number of members in a set.booleanCheck if a key exists.static RedissonClientAdapterof(org.redisson.api.RedissonClient redissonClient) Create adapter from RedissonClient.Get a range of elements from a list.voidrightPushList(String key, String value) Append a value to the right end of a list.voidSet a string value.
-
Method Details
-
of
Create adapter from RedissonClient.The RedissonClient can be configured for any deployment mode (standalone, cluster, sentinel, master/slave), and the adapter will handle the mode-specific details transparently.
- Parameters:
redissonClient- the RedissonClient instance- Returns:
- a new RedissonClientAdapter
-
set
Description copied from interface:RedisClientAdapterSet a string value.- Specified by:
setin interfaceRedisClientAdapter- Parameters:
key- the Redis keyvalue- the string value
-
get
Description copied from interface:RedisClientAdapterGet a string value.- Specified by:
getin interfaceRedisClientAdapter- Parameters:
key- the Redis key- Returns:
- the string value, or null if not found
-
rightPushList
Description copied from interface:RedisClientAdapterAppend a value to the right end of a list.- Specified by:
rightPushListin interfaceRedisClientAdapter- Parameters:
key- the Redis list keyvalue- the value to append
-
rangeList
Description copied from interface:RedisClientAdapterGet a range of elements from a list.- Specified by:
rangeListin interfaceRedisClientAdapter- Parameters:
key- the Redis list keystart- the start index (inclusive)end- the end index (inclusive, -1 for all elements)- Returns:
- list of values
-
getListLength
Description copied from interface:RedisClientAdapterGet the length of a list.- Specified by:
getListLengthin interfaceRedisClientAdapter- Parameters:
key- the Redis list key- Returns:
- the length of the list
-
deleteKeys
Description copied from interface:RedisClientAdapterDelete one or more keys.- Specified by:
deleteKeysin interfaceRedisClientAdapter- Parameters:
keys- the keys to delete
-
addToSet
Description copied from interface:RedisClientAdapterAdd a member to a set.- Specified by:
addToSetin interfaceRedisClientAdapter- Parameters:
key- the Redis set keymember- the member to add
-
getSetMembers
Description copied from interface:RedisClientAdapterGet all members of a set.- Specified by:
getSetMembersin interfaceRedisClientAdapter- Parameters:
key- the Redis set key- Returns:
- set of members
-
getSetSize
Description copied from interface:RedisClientAdapterGet the number of members in a set.- Specified by:
getSetSizein interfaceRedisClientAdapter- Parameters:
key- the Redis set key- Returns:
- the number of members
-
keyExists
Description copied from interface:RedisClientAdapterCheck if a key exists.- Specified by:
keyExistsin interfaceRedisClientAdapter- Parameters:
key- the Redis key- Returns:
- true if the key exists
-
findKeysByPattern
Description copied from interface:RedisClientAdapterFind all keys matching a pattern.- Specified by:
findKeysByPatternin interfaceRedisClientAdapter- Parameters:
pattern- the key pattern (e.g., "prefix:*")- Returns:
- set of matching keys
-
evalScript
Description copied from interface:RedisClientAdapterExecute a Lua script atomically.- Specified by:
evalScriptin interfaceRedisClientAdapter- Parameters:
script- the Lua script sourcekeys- Redis keys passed asKEYSargs- Redis arguments passed asARGV- Returns:
- the script return value as a long
-
close
public void close()Description copied from interface:RedisClientAdapterClose the adapter and release resources.- Specified by:
closein interfaceRedisClientAdapter
-