Skip to main content

Module redis

Module redis 

Source
Expand description

Production Remote adapter over the [redis] crate.

RedisAdapter borrows a connected, caller-owned connection handle: a [ConnectionManager] for standalone or Sentinel-managed servers, a [ClusterConnection] for Redis Cluster, or a plain [MultiplexedConnection]. It never connects, reconnects, drains or closes the handle and never changes its options. The caller remains responsible for:

  • Finite budgets. Configure connection, response and retry limits on the handle (ConnectionManagerConfig::set_response_timeout, ClusterClientBuilder::response_timeout, …). The cache bounds its own wait for reads and honors cooperative cancellation, but cancellation after dispatch cannot prove a command did not execute.
  • Primaries for tracked reads. On a cluster handle the adapter routes every tracked MGET explicitly to the slot primary, so replica lag can never hide an invalidation watermark even when the caller enabled read_from_replicas. A standalone or Sentinel-managed handle must point at the primary itself; the adapter cannot tell a replica apart.
  • Watermark retention. Invalidation stores watermarks with a retention of at least two hours that only widens. Configure eviction so watermark keys are not evicted before tracked values age out; an evicted watermark resurrects fenced values.

Wire behavior matches the TypeScript and Go adapters exactly: an untracked read is one GET; a tracked read is one MGET value watermark on the primary; a write is exactly one native SET key frame PX ttl; an invalidation is EVALSHA of INVALIDATION_SCRIPT with one EVAL retry carrying identical arguments after any EVALSHA failure. Accepted but invalid replies are RedisProtocolErrors and are never retried.

Structs§

RedisAdapter
Remote over a caller-owned redis crate connection handle.
RedisProtocolError
A reply the server accepted but that violates the DialCache wire protocol.
RedisReadCancelled
A read stopped waiting because its ReadContext was cancelled.

Constants§

INVALIDATION_SCRIPT
The version-1 wire invalidation transition, byte-identical to the Go InvalidationScript (a unit test pins this against go/redis_adapter.go). TypeScript’s INVALIDATE_CACHE_SCRIPT is the same Lua with different whitespace and a comment, so its EVALSHA digest differs; every port self-heals through the EVAL fallback, so mixed-language clusters need no shared script cache.

Traits§

RedisConnection
A cloneable, task-shareable handle that runs one Redis command.

Functions§

invalidation_script_sha1
Lowercase hex SHA-1 of INVALIDATION_SCRIPT, the EVALSHA argument.
validate_invalidation_reply
The invalidation script must answer the integer 1.
validate_set_reply
SET must answer OK.