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-kit/redis

Redis for Effect.

A native client with typed commands and scoped connections. One API for every server below.

Supported backends: Redis, Valkey, Dragonfly, KeyDB.RedisValkeyDragonflyKeyDBSupported backends: Redict, Garnet, Apache Kvrocks, Upstash.RedictGarnetApache KvrocksUpstash

When a connection drops

Know whether the write landed.

Before the write: unsent, safe to retry. After it: possibly-written, so it is never sent twice.

SET order:42 paid is queued in the client.
SET order:42 paidqueued637901234567890012345678900123456789001234567890

01Playground

Run it in your browser.

Send
SET
INCR
GET
replies

Simulated Redis: every round trip takes 400ms.

const name = yield* redis.set("{user:42}:name", "Ada");
const visits = yield* redis.incr("{user:42}:visits");
const plan = yield* redis.get("{user:42}:plan");

Inspired by Kit Langton's Visual Effect

02The API

Values keep their shape.

const User = Schema.Struct({ name: Schema.String, active: Schema.Boolean });
const userKey = RedisKey.json("user:42", User);

const saveUser = Effect.gen(function* () {
const redis = yield* Redis;
yield* redis.setKey(userKey, { name: "Ada", active: true });
return yield* redis.getKey(userKey);
// ^? Option<{ name: string; active: boolean }>
});

// Option<{ name: string; active: boolean }>

03Runtimes

Same program on every runtime.

Pick where it runs. Only the Layer changes.

Runtime
  • Commands
  • Pipelines
  • Transactions
  • Pub/Sub, text
  • Binary values
  • WATCH
  • Blocking reads
  • Client tracking
  • Cluster
import { Config, Effect } from "effect";
import { Redis } from "@effect-kit/redis";
import { RedisNode } from "@effect-kit/redis/node";

const program = Effect.gen(function* () {
const redis = yield* Redis;
return yield* redis.incr("visits");
});

const RedisLive = RedisNode.layerConfig(
Config.all({ url: Config.String("REDIS_URL") }),
);

program.pipe(Effect.provide(RedisLive));

04Cluster

Every key goes to its slot.

Type two keys. Put a {hash tag} in both to keep them together.

Hash slot ring. user:1000:name is slot 13514 on node c. user:1000:email is slot 5044 on node a.node a0โ€“5460node b5461โ€“10922node c10923โ€“16383clientb 5044a 13514
slot 13514
slot 5044

Different slots. A command that needs both fails with ClusterError cross-slot before it is sent.

05Supported

Supported integrations.

Servers

  • Redis
  • Valkey
  • Dragonfly
  • KeyDB
  • Redict
  • Garnet
  • Apache Kvrocks

Hosted

  • Upstash
  • Redis Cloud
  • Aiven Valkey

Runtimes

  • Node.js
  • Bun
  • Deno
  • Cloudflare Workers

Get started

Add Redis to your Effect app.

pnpm add @effect-kit/redis effect