Skip to content

feat(session): add support redis session storage#142

Merged
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
jianjun159:main
Dec 8, 2025
Merged

feat(session): add support redis session storage#142
AlbumenJ merged 3 commits intoagentscope-ai:mainfrom
jianjun159:main

Conversation

@jianjun159
Copy link
Contributor

AgentScope-Java Version

[The version of AgentScope-Java you are working on, e.g. 1.0.0, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]
1.0.0
mac os

Description

[Please describe the background, purpose, changes made, and how to test this PR]
add support redis session storage
#128

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

@cla-assistant
Copy link

cla-assistant bot commented Dec 5, 2025

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 73.57860% with 79 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ntscope/core/session/redis/jedis/JedisSession.java 72.25% 23 Missing and 20 partials ⚠️
...e/core/session/redis/redisson/RedissonSession.java 75.00% 21 Missing and 15 partials ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Collaborator

@AlbumenJ AlbumenJ left a comment

Choose a reason for hiding this comment

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

Please add license header & remove all the chinese comments

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds Redis-based session storage support to AgentScope-Java, implementing two Redis client options: Redisson and Jedis. The implementation allows for distributed session management with persistent storage in Redis.

  • Introduces a new extension module for Redis session storage
  • Provides two implementation options: RedissonSession (using Redisson client) and JedisSession (using Jedis client)
  • Includes comprehensive unit tests with mocked Redis clients
  • Adds necessary dependencies (Redisson 3.37.0 and Jedis 5.1.0) to the BOM

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
agentscope-extensions/pom.xml Adds the new session-redis module to the extensions parent POM
agentscope-extensions/agentscope-extensions-session-redis/pom.xml Defines dependencies for the new Redis session extension module
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/redisson/RedissonSession.java Implements Redis-based session storage using the Redisson client with JSON serialization
agentscope-extensions/agentscope-extensions-session-redis/src/main/java/io/agentscope/core/session/redis/jedis/JedisSession.java Implements Redis-based session storage using the Jedis client with JSON serialization
agentscope-extensions/agentscope-extensions-session-redis/src/test/java/io/agentscope/core/session/redis/RedissonSessionTest.java Unit tests for RedissonSession with mocked Redis operations
agentscope-extensions/agentscope-extensions-session-redis/src/test/java/io/agentscope/core/session/redis/JedisSessionTest.java Unit tests for JedisSession with mocked Redis operations
agentscope-dependencies-bom/pom.xml Adds Redisson and Jedis dependency versions to the dependency management BOM

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

class RedissonSessionTest {

private RedissonClient redissonClient;
// 使用原始类型以避免 Mockito 泛型擦除带来的编译问题
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

Comment contains Chinese text that should be translated to English. The comment explains "Use raw types to avoid Mockito generic erasure compilation issues." Consider translating to: // Use raw types to avoid Mockito generic erasure compilation issues

Suggested change
// 使用原始类型以避免 Mockito 泛型擦除带来的编译问题
// Use raw types to avoid Mockito generic erasure compilation issues

Copilot uses AI. Check for mistakes.
Comment on lines 234 to 243
Set<String> keys = jedis.keys(keyPrefix + "*");
for (String key : keys) {
if (key.endsWith(META_SUFFIX)) {
continue;
}
String sessionId = extractSessionId(key);
if (sessionId != null) {
sessionIds.add(sessionId);
}
}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The Jedis keys() command is a blocking operation that scans all keys in Redis and can cause performance issues in production environments with large datasets. Consider using SCAN command instead via jedis.scan() with a cursor to iterate over keys in a non-blocking manner, especially for production use cases.

Suggested change
Set<String> keys = jedis.keys(keyPrefix + "*");
for (String key : keys) {
if (key.endsWith(META_SUFFIX)) {
continue;
}
String sessionId = extractSessionId(key);
if (sessionId != null) {
sessionIds.add(sessionId);
}
}
String cursor = "0";
do {
redis.clients.jedis.ScanResult<String> scanResult = jedis.scan(cursor, keyPrefix + "*");
List<String> keys = scanResult.getResult();
for (String key : keys) {
if (key.endsWith(META_SUFFIX)) {
continue;
}
String sessionId = extractSessionId(key);
if (sessionId != null) {
sessionIds.add(sessionId);
}
}
cursor = scanResult.getCursor();
} while (!"0".equals(cursor));

Copilot uses AI. Check for mistakes.
try (Jedis jedis = getJedisResource()) {
int deletedSessions = 0;

Set<String> keySet = jedis.keys(keyPrefix + "*");
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The Jedis keys() command is a blocking operation that scans all keys in Redis and can cause performance issues in production environments with large datasets. Consider using SCAN command instead via jedis.scan() with a cursor to iterate over keys in a non-blocking manner, especially for production use cases.

Copilot uses AI. Check for mistakes.
Comment on lines 417 to 419
* JedisSession session = JedisSession.builder()
* .host("127.0.0.1")
* .port(6379)
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The usage example shows builder methods .host("127.0.0.1") and .port(6379) that don't exist in the Builder class. The builder only has .jedisPool(JedisPool) and .keyPrefix(String) methods. Update the example to show the correct usage:

JedisPool jedisPool = new JedisPool("127.0.0.1", 6379);
JedisSession session = JedisSession.builder()
    .jedisPool(jedisPool)
    .keyPrefix("agentscope:session:")
    .build();
Suggested change
* JedisSession session = JedisSession.builder()
* .host("127.0.0.1")
* .port(6379)
* JedisPool jedisPool = new JedisPool("127.0.0.1", 6379);
* JedisSession session = JedisSession.builder()
* .jedisPool(jedisPool)

Copilot uses AI. Check for mistakes.
Comment on lines 442 to 443
* RedissonSession session = RedissonSession.builder()
* .address("redis://127.0.0.1:6379")
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The usage example shows a builder method .address("redis://127.0.0.1:6379") that doesn't exist in the Builder class. The builder only has .redissonClient(RedissonClient) and .keyPrefix(String) methods. Update the example to show the correct usage:

Config config = new Config();
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
RedissonClient client = Redisson.create(config);
RedissonSession session = RedissonSession.builder()
    .redissonClient(client)
    .keyPrefix("agentscope:session:")
    .build();
Suggested change
* RedissonSession session = RedissonSession.builder()
* .address("redis://127.0.0.1:6379")
* Config config = new Config();
* config.useSingleServer().setAddress("redis://127.0.0.1:6379");
* RedissonClient client = Redisson.create(config);
* RedissonSession session = RedissonSession.builder()
* .redissonClient(client)

Copilot uses AI. Check for mistakes.
@jianjun159
Copy link
Contributor Author

Please add license header & remove all the chinese comments

Thank you very much for your CR. I have made corresponding changes to the problems encountered during the CR process. Thank you very much again for your CR

@AlbumenJ
Copy link
Collaborator

AlbumenJ commented Dec 8, 2025

@jianjun159 jianjun159 requested a review from a team December 8, 2025 06:26
@jianjun159
Copy link
Contributor Author

@AlbumenJ AlbumenJ merged commit 7c427d0 into agentscope-ai:main Dec 8, 2025
4 checks passed
JGoP-L pushed a commit to JGoP-L/agentscope-java that referenced this pull request Dec 29, 2025
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.

4 participants