Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(session): a unified Redis session client that supports switching between underlying clients#611

Merged
LearningGp merged 27 commits into
agentscope-ai:mainfrom
benym:feat_session_redis
Mar 18, 2026
Merged

feat(session): a unified Redis session client that supports switching between underlying clients#611
LearningGp merged 27 commits into
agentscope-ai:mainfrom
benym:feat_session_redis

Conversation

@benym
Copy link
Copy Markdown
Contributor

@benym benym commented Jan 21, 2026

AgentScope-Java Version

1.0.8-SNAPSHOT

Description

releted to #610

Background

The current JedisSeesion uses JedisPool, which only supports standalone scenarios. In production environments, users mostly use more complex deployment methods, such as sentinels, clusters, and master-slave setups. Furthermore, in a Java environment, users may use different Redis client implementations, such as Jedis, Lettuce, and Redisson. If each is used independently, scaling up with different Redis client implementations would result in a lot of duplicate code. Moreover, naming conventions like JedisSeesion are unclear, as they are all essentially types of Redis clients.

New Feature

  • Unified the RedisSession client: using the adapter pattern to implement different underlying Redis clients, and consolidated the duplicate code that was originally scattered across various client implementations into the RedisSession.
  • Various Redis deployment modes: Jedis, Lettuce, Redisson adopt more modern APIs and support various deployment modes such as standalone, sentinel, cluster, and master-slave.
  • README: Add a README introduction for the agentscope-extensions-session-redis module

The newly added codes all have complete javadoc documentation and the mvn test has passed.

Modify

  • Added lettuce dependency
  • Add the "deprecated" tag to the old versions of JedisSession and RedissonSession, and update the corresponding javadoc.

New Usage

Jedis Usage Examples

  • Jedis Standalone (using RedisClient):
// Create Jedis RedisClient (new API)
RedisClient redisClient = RedisClient.create("redis://localhost:6379");

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisClient)
    .build();
  • Jedis Cluster (using RedisClusterClient)
// Create Jedis RedisClusterClient
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("localhost", 7000));
nodes.add(new HostAndPort("localhost", 7001));
nodes.add(new HostAndPort("localhost", 7002));
RedisClusterClient redisClusterClient = RedisClusterClient.create(nodes);

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisClusterClient)
    .build();
  • Jedis Sentinel (using RedisSentinelClient)
// Create Jedis RedisSentinelClient
Set<String> sentinelNodes = new HashSet<>();
sentinelNodes.add("localhost:26379");
sentinelNodes.add("localhost:26380");
RedisSentinelClient redisSentinelClient = RedisSentinelClient.create("mymaster", sentinelNodes);

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisSentinelClient)
    .build();

Lettuce Usage Examples

  • Lettuce Standalone
// Create Lettuce RedisClient
RedisClient redisClient = RedisClient.create("redis://localhost:6379");

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();
  • Lettuce Cluster
// Create Lettuce RedisClient for cluster
RedisURI clusterUri = RedisURI.create("redis://localhost:7000");
RedisClient redisClient = RedisClient.create(clusterUri);

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();
  • Lettuce Sentinel
// Create Lettuce RedisClient for sentinel
RedisURI sentinelUri = RedisURI.builder()
    .withSentinelMasterId("mymaster")
    .withSentinel("localhost", 26379)
    .withSentinel("localhost", 26380)
    .build();
RedisClient redisClient = RedisClient.create(sentinelUri);

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();

Redisson Usage Example

// Create RedissonClient (configure as needed for your deployment mode)
Config config = new Config();
config.useSingleServer().setAddress("redis://localhost:6379");
// or for cluster: config.useClusterServers().addNodeAddress("redis://localhost:7000");
// or for sentinel: config.useSentinelServers().setMasterName("mymaster").addSentinelAddress("redis://localhost:26379");

RedissonClient redissonClient = Redisson.create(config);

// Build RedisSession
Session session = RedisSession.builder()
    .redissonClient(redissonClient)
    .build();

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

@benym benym requested a review from a team January 21, 2026 02:13
@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Jan 21, 2026

CLA assistant check
All committers have signed the CLA.

@cla-assistant
Copy link
Copy Markdown

cla-assistant Bot commented Jan 21, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @benym, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Redis session management within AgentScope by introducing a unified RedisSession client. This new implementation leverages an adapter pattern to abstract away the underlying Redis client library, enabling seamless integration with Jedis, Lettuce, and Redisson, and supporting diverse Redis deployment topologies like standalone, cluster, and sentinel. This change streamlines the session management API, reduces code duplication, and improves flexibility for users operating in various production environments.

Highlights

  • Unified Redis Session Client: Introduced a new RedisSession class that uses an adapter pattern to provide a single, consistent API for interacting with different Redis client implementations.
  • Multi-Client Support: The new RedisSession now natively supports Jedis, Lettuce, and Redisson clients, allowing users to choose their preferred Redis client.
  • Flexible Deployment Modes: The unified client supports various Redis deployment modes, including standalone, sentinel, cluster, and master-slave configurations, addressing limitations of previous implementations.
  • Deprecation of Old Sessions: The existing JedisSession and RedissonSession classes have been deprecated, guiding users towards the new unified RedisSession.
  • Enhanced Documentation: Comprehensive README.md and README_zh.md files have been added to the agentscope-extensions-session-redis module, providing detailed usage examples and explanations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@benym
Copy link
Copy Markdown
Contributor Author

benym commented Jan 21, 2026

ptal,thx @AlbumenJ @chickenlj

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a unified RedisSession client, which is a significant improvement for supporting various Redis clients (Jedis, Lettuce, Redisson) and deployment modes. The use of the adapter pattern is well-executed. I've identified a few areas for improvement, primarily concerning performance and documentation accuracy. The Jedis and Lettuce adapters currently use the KEYS command, which can pose a performance risk in production; I've suggested switching to SCAN. Additionally, there are some inaccuracies in Javadoc and README examples that should be corrected for clarity. Overall, this is a great feature addition.

Comment thread agentscope-extensions/agentscope-extensions-session-redis/README.md Outdated
Comment thread agentscope-extensions/agentscope-extensions-session-redis/README_zh.md Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 21, 2026

@benym
Copy link
Copy Markdown
Contributor Author

benym commented Jan 22, 2026

done. please check again. @AlbumenJ

@benym benym requested a review from AlbumenJ January 27, 2026 05:38
@benym
Copy link
Copy Markdown
Contributor Author

benym commented Mar 10, 2026

I made the following modifications, please review again @LearningGp :

  • Added LettuceClientAdapter of(RedisClient redisClient) and LettuceClientAdapter of(RedisClusterClient redisClusterClient) to adapt clients for standalone/sentinel and cluster.
  • Use RedisCommands for standalone/sentinel and RedisAdvancedClusterCommands for cluster.
  • Added lettuceClusterClient Builder assignment to RedisSession.

@benym benym requested a review from LearningGp March 10, 2026 15:18
Copy link
Copy Markdown
Collaborator

@LearningGp LearningGp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp LearningGp merged commit 09b9780 into agentscope-ai:main Mar 18, 2026
6 checks passed
@benym benym deleted the feat_session_redis branch March 19, 2026 02:12
liangxingguang pushed a commit to liangxingguang/agentscope-java that referenced this pull request May 21, 2026
… between underlying clients (agentscope-ai#611)

## AgentScope-Java Version

1.0.8-SNAPSHOT

## Description

releted to agentscope-ai#610 

### Background

The current JedisSeesion uses JedisPool, which only supports standalone
scenarios. In production environments, users mostly use more complex
deployment methods, such as sentinels, clusters, and master-slave
setups. Furthermore, in a Java environment, users may use different
Redis client implementations, such as `Jedis`, `Lettuce`, and
`Redisson`. If each is used independently, scaling up with different
Redis client implementations would result in `a lot of duplicate code`.
Moreover, naming conventions like JedisSeesion are unclear, as they are
all essentially types of Redis clients.

### New Feature

- **Unified the RedisSession client**: using the adapter pattern to
implement different underlying Redis clients, and consolidated the
duplicate code that was originally scattered across various client
implementations into the RedisSession.
- **Various Redis deployment modes**: Jedis, Lettuce, Redisson adopt
more modern APIs and support various deployment modes such as
standalone, sentinel, cluster, and master-slave.
- **README**: Add a README introduction for the
`agentscope-extensions-session-redis` module

The newly added codes all have complete javadoc documentation and the
`mvn test` has passed.

### Modify

- Added lettuce dependency
- Add the "deprecated" tag to the old versions of JedisSession and
RedissonSession, and update the corresponding javadoc.

### New Usage

#### Jedis Usage Examples

- Jedis Standalone (using RedisClient):

```java
// Create Jedis RedisClient (new API)
RedisClient redisClient = RedisClient.create("redis://localhost:6379");

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisClient)
    .build();
```

- Jedis Cluster (using RedisClusterClient)

```java
// Create Jedis RedisClusterClient
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("localhost", 7000));
nodes.add(new HostAndPort("localhost", 7001));
nodes.add(new HostAndPort("localhost", 7002));
RedisClusterClient redisClusterClient = RedisClusterClient.create(nodes);

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisClusterClient)
    .build();
```

- Jedis Sentinel (using RedisSentinelClient)

```java
// Create Jedis RedisSentinelClient
Set<String> sentinelNodes = new HashSet<>();
sentinelNodes.add("localhost:26379");
sentinelNodes.add("localhost:26380");
RedisSentinelClient redisSentinelClient = RedisSentinelClient.create("mymaster", sentinelNodes);

// Build RedisSession
Session session = RedisSession.builder()
    .jedisClient(redisSentinelClient)
    .build();
```

#### Lettuce Usage Examples

- Lettuce Standalone

```java
// Create Lettuce RedisClient
RedisClient redisClient = RedisClient.create("redis://localhost:6379");

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();
```

- Lettuce Cluster

```java
// Create Lettuce RedisClient for cluster
RedisURI clusterUri = RedisURI.create("redis://localhost:7000");
RedisClient redisClient = RedisClient.create(clusterUri);

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();
```

- Lettuce Sentinel

```java
// Create Lettuce RedisClient for sentinel
RedisURI sentinelUri = RedisURI.builder()
    .withSentinelMasterId("mymaster")
    .withSentinel("localhost", 26379)
    .withSentinel("localhost", 26380)
    .build();
RedisClient redisClient = RedisClient.create(sentinelUri);

// Build RedisSession
Session session = RedisSession.builder()
    .lettuceClient(redisClient)
    .build();
```

#### Redisson Usage Example

```java
// Create RedissonClient (configure as needed for your deployment mode)
Config config = new Config();
config.useSingleServer().setAddress("redis://localhost:6379");
// or for cluster: config.useClusterServers().addNodeAddress("redis://localhost:7000");
// or for sentinel: config.useSentinelServers().setMasterName("mymaster").addSentinelAddress("redis://localhost:26379");

RedissonClient redissonClient = Redisson.create(config);

// Build RedisSession
Session session = RedisSession.builder()
    .redissonClient(redissonClient)
    .build();
```

## Checklist

Please check the following items before code is ready to be reviewed.

- [x] Code has been formatted with `mvn spotless:apply`
- [x] All tests are passing (`mvn test`)
- [x] Javadoc comments are complete and follow project conventions
- [x] Related documentation has been updated (e.g. links, examples,
etc.)
- [x] Code is ready for review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants