feat(redis): add shard-aware key schema, Lua scripts, and atomic ops

Implements the kmsvc: key schema (inflight, pending/watermark keyed by
shard+partition, vis_index, dedup, fifo_lock, queue meta, shard map) plus
the atomic reap/ack Lua scripts used for safe multi-replica redelivery
and DLQ routing.
This commit is contained in:
riotpiaole
2026-06-21 17:05:38 -07:00
parent b704d401a1
commit a04c76a684
12 changed files with 927 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
package redis
import (
"context"
"fmt"
"time"
"github.com/redis/go-redis/v9"
)
// TryDedup attempts to claim a MessageDeduplicationId for a FIFO MessageGroupId
// (design.md §4 `kmsvc:dedup:` row). Returns true if this is the first send
// within the dedup window (the message should be accepted), false if it's a
// duplicate (the message should be silently deduped).
func TryDedup(ctx context.Context, rdb *redis.Client, queue, groupID, dedupID string, window time.Duration) (bool, error) {
ok, err := rdb.SetNX(ctx, DedupKey(queue, groupID, dedupID), "1", window).Result()
if err != nil {
return false, fmt.Errorf("dedup check %s/%s: %w", groupID, dedupID, err)
}
return ok, nil
}