Class RedisIdempotencyStore

java.lang.Object
com.tnsai.idempotency.RedisIdempotencyStore
All Implemented Interfaces:
IdempotencyStore

public final class RedisIdempotencyStore extends Object implements IdempotencyStore
Distributed IdempotencyStore backed by Redis (issue #91). Use this when the framework runs as more than one process and dedup needs to survive a crash or a horizontal restart.

Commands use the caller-owned, pooled RedisClient, so the store can be shared across threads. The caller closes the client at application shutdown; store operations never close it. TTL is enforced server-side via SET ... EX ..., so stale entries need no sweep.

Entries are JSON-encoded by IdempotencyEntryCodec. The round-trip is generic-JSON (not type-preserving): a typed POJO cached in process A and read in process B comes back as a Map/List mosaic. Consumers needing the original type should re-marshal at the call site.

Optional dependency

Jedis is declared as an <optional> dependency on tnsai-core: consumers add it themselves to opt in. Loading this class without Jedis on the classpath is a hard NoClassDefFoundError -- by design, since the store cannot function without it.

Key prefix

The configured prefix is prepended to every key the store touches, giving operators a way to share a Redis instance across multiple unrelated TnsAI deployments. Default "tnsai:idem:" is safe for sole-tenant Redis but should be customised for shared clusters.
Since:
0.10.0 (issue #91 closeout)
  • Field Details

    • DEFAULT_KEY_PREFIX

      public static final String DEFAULT_KEY_PREFIX
      Default key prefix; safe for sole-tenant Redis.
      See Also:
  • Constructor Details

    • RedisIdempotencyStore

      public RedisIdempotencyStore(redis.clients.jedis.RedisClient client)
      Uses DEFAULT_KEY_PREFIX with a caller-owned client; the store never closes it.
      Since:
      0.17.5
    • RedisIdempotencyStore

      public RedisIdempotencyStore(redis.clients.jedis.RedisClient client, String keyPrefix)
      Uses a caller-owned client; the store never closes it.
      Since:
      0.17.5
  • Method Details