Documentation for agents: an index at /llms.txt, every docs page in one file at /llms-full.txt, and Markdown for any docs page by adding .md to its URL.

Effect KitRedis

Client-side caching

Keep recently read values in memory and drop them when the server reports a change.

Client-side caching keeps values from GET in process memory. The server tracks which keys the connection read and sends an invalidation when one changes, so a cached entry is dropped as soon as someone writes the key. RedisCache is a bounded cache of GET replies built on RedisTracking.

Not in the default layer

RedisNode.layer and RedisBun.layer do not provide RedisTracking or RedisCache. You add them yourself, with a decoded config and the socket transport. Native sockets only: Upstash over HTTP has no tracking.

Adding the layers

RedisTracking.layer(config) needs a RedisConfig from decodeRedisConfig and the Transport. The layer exported from @effect-kit/redis/node or @effect-kit/redis/bun is that transport. RedisCache.layer(options) sits on top of RedisTracking.

Example (Building a Cache Layer for Node.js)

import { ,  } from "effect";

import { , ,  } from "@effect-kit/redis";
import {  as  } from "@effect-kit/redis/node";

const  = .(
  ({ : { : "redis://localhost:6379" } }).(
    .(() => .()),
  ),
);

export const  = .({ : 500 }).(
  .(),
  .(),
);

The tracking connection is separate from your command connections. You can run it next to RedisNode.layer in the same program.

Reading through the cache

The cache offers getBytes, and getKey for a typed key. The first read goes to the server and fills the cache. Later reads of the same key are served from memory until an invalidation arrives or the entry expires.

Example (Reading a Typed Key Through the Cache)

import { ,  } from "effect";

import { , RedisKey } from "@effect-kit/redis";

const  = .({ : . });
const  = RedisKey.("profile:42", );

const  = .(function* () {
  const  = yield* ;

  const profile = yield* .();
const profile: Option<{
    readonly name: string;
}>
const = yield* .(); return { , }; });

A key that does not exist is cached too, as None. A write from the same process through tracking.execute is visible on the next read. FLUSHDB sends an invalidation with no key list, which clears the whole cache.

Cache limits

CacheOptions bounds the cache. Every field is optional.

Prop

Type

cache.snapshot reports entries, bytes, inFlight and active, and cache.clear empties it.

Invalidation events

RedisTracking exposes events, a Stream of Invalidate, TrackingGap and TrackingReady. An Invalidate carries the changed keys, or null when everything is invalid. The invalidations stream carries only Invalidate and fails with a SubscriptionError whose reason is "tracking-lost" when the connection loses tracking.