LettuceClientAdapter
public class LettuceClientAdapter implements RedisClientAdapter
io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:93–336Lettuce 客户端适配器,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.core.session.redis.lettuce 包,实现 RedisClientAdapter。核心成员包括 of、set、get、rightPushList、rangeList、getListLength。
Adapter for Lettuce Redis client.
This adapter supports multiple Redis deployment modes through different client types:
-
RedisClient- Standalone and Sentinel modes -
RedisClusterClient- Cluster mode
The adapter internally manages a shared connection and commands instance for efficient connection usage.
This implementation uses direct conditional checks to handle Lettuce's separate command APIs for standalone/sentinel and cluster modes. This is the simplest approach given Lettuce's lack of a unified API across deployment modes.
Usage Examples:
Standalone Mode:
`// Create standalone RedisClient
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
// Use with RedisSession
Session session = RedisSession.builder()
.lettuceClient(redisClient)
.build();
`
Cluster Mode:
`// Create cluster client
RedisClusterClient clusterClient = RedisClusterClient.create("redis://localhost:7000");
// Use with RedisSession
Session session = RedisSession.builder()
.lettuceClusterClient(clusterClient)
.build();
`
Sentinel Mode:
`// Create Lettuce RedisClient for sentinel
RedisURI sentinelUri = RedisURI.builder()
.withSentinelMasterId("mymaster")
.withSentinel("localhost", 26379)
.withSentinel("localhost", 26380)
.withSentinel("localhost", 26381)
.withDatabase(0)
.build();
RedisClient redisClient = RedisClient.create(sentinelUri);
// Use with RedisSession
Session session = RedisSession.builder()
.lettuceClient(redisClient)
.build();
`
方法摘要Method Summary
方法详情Method Detail
of
public static LettuceClientAdapter of(RedisClient redisClient)
创建并返回实例。
Create adapter from RedisClient (standalone/sentinel mode).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
redisClient | RedisClient | Redis 客户端(类型 `RedisClient`)。the RedisClient for standalone or sentinel mode |
LettuceClientAdapterNullPointerException可能抛出 `NullPointerException`。if redisClient is null
io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:132–139of
public static LettuceClientAdapter of(RedisClusterClient redisClusterClient)
创建适配器来自 RedisClusterClient(集群模式)。
Create adapter from RedisClusterClient (cluster mode).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
redisClusterClient | RedisClusterClient | RedisClusterClient 用于集群模式。the RedisClusterClient for cluster mode |
LettuceClientAdapterNullPointerException可能抛出 `NullPointerException`。if redisClusterClient is null
io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:148–155set
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/lettuce/LettuceClientAdapter.java:157–164get
public String get(String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Stringio/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:166–173rightPushList
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/lettuce/LettuceClientAdapter.java:175–182rangeList
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/lettuce/LettuceClientAdapter.java:184–191getListLength
public long getListLength(String key)
获取列表长度。
Returns the list length.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:193–200deleteKeys
public void deleteKeys(String... keys)
删除密钥。
Deletes the keys.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keys varargs | String... | 密钥(类型 `String...`)。The keys. |
io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:202–209addToSet
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/lettuce/LettuceClientAdapter.java:211–218getSetMembers
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/lettuce/LettuceClientAdapter.java:220–227getSetSize
public long getSetSize(String key)
获取设置大小。
Returns the set size.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:229–236keyExists
public boolean keyExists(String key)
设置该参数。
Performs the key exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
booleanio/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:238–245findKeysByPattern
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/lettuce/LettuceClientAdapter.java:247–254close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/core/session/redis/lettuce/LettuceClientAdapter.java:283–293