spring-projects / spring-projects/spring-data-redis

Add support for XAUTOCLAIM to stream operations

Open
#3,434 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
1.9k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

Description

Hello!

Redis 6.2 added XAUTOCLAIM, which transfers ownership of pending entries that have been idle for longer than a given time, scanning the pending entries list with a cursor instead of requiring the caller to name the record ids up front.

Spring Data Redis exposes XCLAIM (RedisStreamCommands#xClaim, StreamOperations#claim) but not XAUTOCLAIM. To recover messages left behind by a dead consumer today you either call XPENDING first and feed the ids into claim, or drop out of the abstraction entirely:

RedisConnection connection = factory.getConnection();
var nativeCommands = (RedisClusterAsyncCommands<byte[], byte[]>) connection.getNativeConnection();

ClaimedMessages<byte[], byte[]> claimed = nativeCommands
        .xautoclaim("orders".getBytes(),
                XAutoClaimArgs.Builder.xautoclaim(consumer, Duration.ofMinutes(5), "0-0"))
        .get();

That ties the recovery code to one driver and bypasses the serializers configured on the template.

Both drivers pinned in pom.xml already support the command:

cursor claimed entries
Lettuce 7.7.0.RELEASE, xautoclaim(K, XAutoClaimArgs<K>) -> ClaimedMessages yes yes
Jedis 8.0.1, xautoclaim / xautoclaimJustId -> Map.Entry<StreamEntryID, ...> yes yes

Feature request: expose XAUTOCLAIM alongside the existing claim methods, on RedisStreamCommands / ReactiveStreamCommands and on StreamOperations / ReactiveStreamOperations, for both drivers.

One design note, since it affects the signatures. XAUTOCLAIM returns a cursor in addition to the claimed entries, and a cursor of 0-0 is what tells the caller the scan is finished. Returning a bare List or Flux of records the way claim does would drop that, so I would return a small value object holding the next cursor plus the claimed records, with a JUSTID variant holding the ids, and have the reactive side return Mono<...> rather than Flux<...> so the cursor survives.

Out of scope: the third reply element added in Redis 7.0, the ids of pending entries that no longer exist in the stream. Neither pinned driver exposes it today. The Lettuce side is fixed in redis/lettuce#3901 and ships in 7.8, so I would leave it out for now rather than add an accessor that is always empty, and add it once the driver is upgraded here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with RedisStreamCommands#xClaim and StreamOperations#claim, then compare their reactive counterparts and the Lettuce and Jedis support described in pom.xml. Done means both synchronous and reactive stream APIs expose XAUTOCLAIM for both drivers, preserving the next cursor and claimed records or ids while excluding the Redis 7.0 third reply element.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, redis, spring
Domain
api, backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.