Repository navigation
feat(redis): support Lettuce clients in RedisSnapshotSpec - #3822
Merged
Merged
Conversation
Add LettuceRemoteSnapshotClient, a RemoteSnapshotClient backed by Redis binary values through Lettuce sync commands, and expose it via new RedisSnapshotSpec overloads accepting RedisCommands (standalone and sentinel) and RedisAdvancedClusterCommands (cluster). The Jedis path and the key layout, prefix normalization, and TTL semantics stay unchanged. Fixes agentscope-ai#1596
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Contributor
Author
|
Hi @jujn, could you please review this PR when you have time, or help route it to the appropriate Redis maintainer? It implements the Lettuce snapshot support requested in #1596 while preserving the existing Jedis behavior. Java CI and Mintlify docs validation are green on the current head, and the CLA check is passing. Thank you! |
jujn
approved these changes
Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(redis): support Lettuce clients in RedisSnapshotSpec
AgentScope-Java Version
2.1.0-SNAPSHOT (main @ 16cb024), Java 17
Description
RedisSnapshotSpec/RedisRemoteSnapshotClientonly accepted a JedisUnifiedJedisclient, although the module already ships a Lettuce dependency (used by
LettuceClientAdapterfor state storage). Applications that standardize on Lettuce hadto keep a second Redis client around just for sandbox snapshots.
This PR adds a Lettuce implementation of the same snapshot/spec contract:
LettuceRemoteSnapshotClient— aRemoteSnapshotClientbacked by Redis binaryvalues through Lettuce. It accepts
RedisCommands<byte[], byte[]>(standalone/Sentinel) or
RedisAdvancedClusterCommands<byte[], byte[]>(cluster),mirroring the client types already supported by
LettuceClientAdapter.RedisSnapshotSpecgains two overloaded constructors taking those Lettuce synccommand APIs. The existing Jedis constructor and
RedisRemoteSnapshotClientareuntouched.
The observable behavior matches the Jedis implementation exactly: key layout
<prefix><snapshotId>.tar, default prefixagentscope:sandbox:snapshots:, prefixnormalization (trailing
:appended when missing), TTL semantics (null or <= 0 means noTTL),
FileNotFoundExceptionon missing snapshot download, and the blank-snapshotIdguard.
Design notes:
RemoteSnapshotClientexposes a blockingInputStreamcontract, so commands block the calling thread exactly like the Jedisimplementation, while Lettuce's own IO threads stay non-blocking. Lettuce connections
are thread-safe, so a single client is shared across sessions.
RedisURItimeout configured on the client (default 60s),which replaces Jedis' socket timeouts.
RemoteSnapshotClienthas noclose hook, and the Jedis implementation equally leaves its
UnifiedJedisopen.RedisAdvancedClusterCommands, which handles slotredirection transparently, so no extra CROSSSLOT handling is needed.
Docs:
docs/v2/{en,zh}/integration/distributed/redis.mdnow show the Lettuce usage nextto the existing Jedis snippet.
Fixes #1596
How to test
mvn -T1C -pl agentscope-extensions/agentscope-extensions-redis -am testNew unit tests in
LettuceRemoteSnapshotClientTest(mocked Lettuce commands, followingthe module's existing JUnit 5 + Mockito style): upload writes the composed key and skips
TTL when absent, positive TTL applied with normalized prefix, non-positive TTL ignored,
blank snapshotId rejected before touching Redis, download round-trip and
missing-key failure, exists delegation, cluster-command constructor, null rejection, and
spec wiring.
Verified locally on 2026-10-27 (macOS arm64, JDK 17.0.20.1 at
/opt/homebrew/opt/openjdk@17, Maven 3.10.0; the repo has no mvnw wrapper):
mvn -B -T1C -pl agentscope-extensions/agentscope-extensions-redis -am test—BUILD SUCCESS (reactor: dependencies-bom, bom, parent, core, extensions, protocol,
ag-ui, harness, redis — all SUCCESS). Module result:
Tests run: 35, Failures: 0, Errors: 0, Skipped: 1. The single skip isRedisSessionStorageIntegrationTest.independentClientsRaceCasAndRecoverTheFencedCommittedPrefix,gated by
@EnabledIfEnvironmentVariable(named = "AGENTSCOPE_TEST_REDIS_URL"), i.e.it only runs when a real Redis URL is provided.
mvn -B -pl agentscope-extensions/agentscope-extensions-redis spotless:check—BUILD SUCCESS,
Spotless.Java is keeping 23 files clean - 0 needs changes to be clean. Spotlesscheckis also bound to thecompilephase in the root pom, so itran (and passed) for every module in the
-amreactor during the test build above.Note: this repo does not configure a checkstyle plugin; spotless is the formatter
gate.
Checklist
Please check the following items before code is ready to be reviewed.
mvn spotless:applymvn test)