JedisClientAdapter
public class JedisClientAdapter implements RedisClientAdapter
io/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:86–184Jedis 客户端适配器,在多次调用之间保存和恢复会话与记忆数据。位于 io.agentscope.extensions.redis.state.jedis 包,实现 RedisClientAdapter。核心成员包括 of、set、get、rightPushList、rangeList、getListLength。
Adapter for Jedis Redis client.
This adapter supports all Jedis client types:
-
RedisClient- Standalone client -
RedisClusterClient- Cluster client -
RedisSentinelClient- Sentinel client -
UnifiedJedis- Base unified interface
All new client types extend UnifiedJedis, providing a unified interface that
handles different Redis deployment modes transparently.
Usage examples:
Using RedisClient (Standalone):
`// Create standalone client
RedisClient redisClient = RedisClient.create("redis://localhost:6379");
// Create adapter
JedisClientAdapter adapter = JedisClientAdapter.of(redisClient);
`
Using RedisClusterClient (Cluster):
`// Create cluster client
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("localhost", 7000));
nodes.add(new HostAndPort("localhost", 7001));
RedisClusterClient clusterClient = RedisClusterClient.create(nodes);
// Create adapter
JedisClientAdapter adapter = JedisClientAdapter.of(clusterClient);
`
Using RedisSentinelClient (Sentinel):
`// Create sentinel client
Set<String> sentinels = new HashSet<>();
sentinels.add("localhost:26379");
RedisSentinelClient sentinelClient = RedisSentinelClient.create("mymaster", sentinels);
// Create adapter
JedisClientAdapter adapter = JedisClientAdapter.of(sentinelClient);
`
Using UnifiedJedis (Direct):
`// Create any client type that extends UnifiedJedis
UnifiedJedis unifiedJedis = new RedisClient("redis://localhost:6379");
// Create adapter
JedisClientAdapter adapter = JedisClientAdapter.of(unifiedJedis);
`
方法摘要Method Summary
方法详情Method Detail
of
public static JedisClientAdapter of(UnifiedJedis unifiedJedis)
创建适配器来自 UnifiedJedis。
Create adapter from UnifiedJedis.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
unifiedJedis | UnifiedJedis | 统一 Jedis(类型 `UnifiedJedis`)。the UnifiedJedis instance (any subclass) |
JedisClientAdapterio/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:100–102set
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/jedis/JedisClientAdapter.java:104–107get
public String get(String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
Stringio/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:109–112rightPushList
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/jedis/JedisClientAdapter.java:114–117rangeList
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/jedis/JedisClientAdapter.java:119–122getListLength
public long getListLength(String key)
获取列表长度。
Returns the list length.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:124–127deleteKeys
public void deleteKeys(String... keys)
删除密钥。
Deletes the keys.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keys varargs | String... | 密钥(类型 `String...`)。The keys. |
io/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:129–132addToSet
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/jedis/JedisClientAdapter.java:134–137getSetMembers
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/jedis/JedisClientAdapter.java:139–142getSetSize
public long getSetSize(String key)
获取设置大小。
Returns the set size.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
longio/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:144–147keyExists
public boolean keyExists(String key)
设置该参数。
Performs the key exists operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
key | String | 键(类型 `String`)。The key. |
booleanio/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:149–152findKeysByPattern
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/jedis/JedisClientAdapter.java:154–169evalScript
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/jedis/JedisClientAdapter.java:171–178close
public void close()
关闭连接并释放相关资源。
Releases resources and connections.
io/agentscope/extensions/redis/state/jedis/JedisClientAdapter.java:180–183