Skip to content

feat(redis): support Lettuce clients in RedisSnapshotSpec - #3822

Merged
jujn merged 1 commit into
agentscope-ai:mainfrom
PoisonGodv:feat-1596-lettuce-snapshot
Nov 12, 2026
Merged

jujn merged 1 commit into
agentscope-ai:mainfrom
PoisonGodv:feat-1596-lettuce-snapshot

Conversation

@PoisonGodv

Copy link
Copy Markdown
Contributor

feat(redis): support Lettuce clients in RedisSnapshotSpec

AgentScope-Java Version

2.1.0-SNAPSHOT (main @ 16cb024), Java 17

Description

RedisSnapshotSpec / RedisRemoteSnapshotClient only accepted a Jedis UnifiedJedis
client, although the module already ships a Lettuce dependency (used by
LettuceClientAdapter for state storage). Applications that standardize on Lettuce had
to keep a second Redis client around just for sandbox snapshots.

This PR adds a Lettuce implementation of the same snapshot/spec contract:

  • New LettuceRemoteSnapshotClient — a RemoteSnapshotClient backed by Redis binary
    values through Lettuce. It accepts RedisCommands<byte[], byte[]>
    (standalone/Sentinel) or RedisAdvancedClusterCommands<byte[], byte[]> (cluster),
    mirroring the client types already supported by LettuceClientAdapter.
  • RedisSnapshotSpec gains two overloaded constructors taking those Lettuce sync
    command APIs. The existing Jedis constructor and RedisRemoteSnapshotClient are
    untouched.

The observable behavior matches the Jedis implementation exactly: key layout
<prefix><snapshotId>.tar, default prefix agentscope:sandbox:snapshots:, prefix
normalization (trailing : appended when missing), TTL semantics (null or <= 0 means no
TTL), FileNotFoundException on missing snapshot download, and the blank-snapshotId
guard.

Design notes:

  • The blocking sync API is used on purpose: RemoteSnapshotClient exposes a blocking
    InputStream contract, so commands block the calling thread exactly like the Jedis
    implementation, while Lettuce's own IO threads stay non-blocking. Lettuce connections
    are thread-safe, so a single client is shared across sessions.
  • Command timeouts follow the RedisURI timeout configured on the client (default 60s),
    which replaces Jedis' socket timeouts.
  • The connection/client lifecycle stays with the caller: RemoteSnapshotClient has no
    close hook, and the Jedis implementation equally leaves its UnifiedJedis open.
  • Cluster mode goes through RedisAdvancedClusterCommands, which handles slot
    redirection transparently, so no extra CROSSSLOT handling is needed.

Docs: docs/v2/{en,zh}/integration/distributed/redis.md now show the Lettuce usage next
to the existing Jedis snippet.

Fixes #1596

How to test

mvn -T1C -pl agentscope-extensions/agentscope-extensions-redis -am test

New unit tests in LettuceRemoteSnapshotClientTest (mocked Lettuce commands, following
the 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 is
    RedisSessionStorageIntegrationTest.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. Spotless check is also bound to the compile phase in the root pom, so it
    ran (and passed) for every module in the -am reactor 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.

  • 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

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
@mintlify

mintlify Bot commented Oct 28, 2026

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 6927bd3.

Approve preview

@CLAassistant

CLAassistant commented Oct 28, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jujn jujn added the P2 重要不紧急 label Nov 3, 2026
@PoisonGodv

Copy link
Copy Markdown
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
jujn merged commit ca5a2d3 into agentscope-ai:main Nov 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: RedisSnapshotSpec 为什么不支持lettuce的客户端

3 participants