RedissonClientAdapter
public class RedissonClientAdapter implements RedisClientAdapter
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:119–241Redisson 客户端适配器,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.extensions.redis.state.redisson 包,实现 RedisClientAdapter。核心成员包括 of、set、get、rightPushList、rangeList、getListLength。
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
方法详情Method Detail
of
public static RedissonClientAdapter of(RedissonClient redissonClient)
创建适配器来自 RedissonClient。
Create adapter from RedissonClient.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
redissonClient | RedissonClient | RedissonClient 实例。the RedissonClient instance |
RedissonClientAdapterio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:136–138set
public void set(String key, String value)
执行设置相关操作。
Performs the set operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
value | String | 值(类型 `String`)。The value. |
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:140–144get
public String get(String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Stringio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:146–150rightPushList
public void rightPushList(String key, String value)
执行 rightPushList 方法。
Performs the right push list operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
value | String | 值(类型 `String`)。The value. |
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:152–156rangeList
public List<String> rangeList(String key, long start, long end)
执行 rangeList 方法。
Performs the range list operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
start | long | 启动(类型 `long`)。The start. |
end | long | 结束(类型 `long`)。The end. |
List<String>io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:158–169getListLength
public long getListLength(String key)
获取列表长度。
Returns the list length.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:171–175deleteKeys
public void deleteKeys(String... keys)
删除密钥。
Deletes the keys.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keys varargs | String... | 密钥(类型 `String...`)。The keys. |
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:177–181addToSet
public void addToSet(String key, String member)
添加到设置。
Adds the to set.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
member | String | 成员(类型 `String`)。The member. |
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:183–187getSetMembers
public Set<String> getSetMembers(String key)
获取设置成员。
Returns the set members.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Set<String>io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:189–193getSetSize
public long getSetSize(String key)
获取设置大小。
Returns the set size.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:195–199keyExists
public boolean keyExists(String key)
设置该参数。
Performs the key exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
booleanio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:201–205findKeysByPattern
public Set<String> findKeysByPattern(String pattern)
查找 findKeysByPattern。
Finds the keys by pattern.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
pattern | String | pattern(类型 `String`)。The pattern. |
Set<String>io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:207–217evalScript
public long evalScript(String script, List<String> keys, List<String> args)
执行 evalScript 方法。
Performs the eval script operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
script | String | script(类型 `String`)。The script. |
keys | List<String> | 密钥(类型 `List`)。The keys. |
args | List<String> | 参数(类型 `List`)。The args. |
longio/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:219–235close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/extensions/redis/state/redisson/RedissonClientAdapter.java:237–240