RedissonClientAdapter
public class RedissonClientAdapter implements RedisClientAdapter
io/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:117–221Redisson 客户端适配器,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.session.redis.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 RedisSession
Session session = RedisSession.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/core/session/redis/redisson/RedissonClientAdapter.java:134–136set
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/core/session/redis/redisson/RedissonClientAdapter.java:138–142get
public String get(String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Stringio/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:144–148rightPushList
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/core/session/redis/redisson/RedissonClientAdapter.java:150–154rangeList
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/core/session/redis/redisson/RedissonClientAdapter.java:156–167getListLength
public long getListLength(String key)
获取列表长度。
Returns the list length.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:169–173deleteKeys
public void deleteKeys(String... keys)
删除密钥。
Deletes the keys.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keys varargs | String... | 密钥(类型 `String...`)。The keys. |
io/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:175–179addToSet
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/core/session/redis/redisson/RedissonClientAdapter.java:181–185getSetMembers
public Set<String> getSetMembers(String key)
获取设置成员。
Returns the set members.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Set<String>io/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:187–191getSetSize
public long getSetSize(String key)
获取设置大小。
Returns the set size.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:193–197keyExists
public boolean keyExists(String key)
设置该参数。
Performs the key exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
booleanio/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:199–203findKeysByPattern
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/core/session/redis/redisson/RedissonClientAdapter.java:205–215close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/core/session/redis/redisson/RedissonClientAdapter.java:217–220