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

Commands

Call commands as methods on the Redis service, as pure values, or as raw tokens.

Every Redis command is available three ways: as a method on redis, as a pure Commands.* value you pass to redis.execute, or as raw tokens through redis.raw. All three go through the same executor and fail with the same typed errors. Per-family method lists are in the Commands reference.

Example (Calling a Command as a Method and as a Value)

import {  } from "effect";

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

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

  const viaMethod = yield* .("user:42:name");
const viaMethod: Option<string>
const viaValue = yield* .(Commands.("user:42:name"));
const viaValue: Option<string>
return [, ] as ; });

redis.get("k") and redis.execute(Commands.get("k")) are the same call. A Commands.* value does nothing until something runs it, so you can build commands ahead of time and hand them to redis.pipeline, redis.transaction or redis.execute.

How results are typed

The success type follows the command and its options.

  • redis.get returns Option<string> and redis.getBytes returns Option<Uint8Array>.
  • Integer replies such as incr, hset, zadd and del return bigint.
  • Keys and values accept string or Uint8Array.
  • redis.set returns void. With a literal condition it returns boolean. With { get: true } it returns the previous value as Option<Uint8Array>.

Example (Typing a Conditional Write)

import {  } from "effect";

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

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

  const created = yield* .("lock:report", "worker-1", { : "NX" });
const created: boolean
const previous = yield* .("mode", "fast", { : true });
const previous: Option<Uint8Array<ArrayBufferLike>>
return { , }; });

created is true when the key was set and false when NX found it already present. Previous bytes do not prove that a condition applied.

expiryAfter(Duration) builds an expiry from an Effect Duration. It rejects durations below one millisecond.

Defining a command

defineCommand builds a Command from metadata, tokens, routing and a reply decoder. Use it for a command the package does not ship, such as one from a server module.

The Reply namespace has the decoders: blob, text, integer, safeInteger, status, optional, array, score, boolean, nullable, pairs and more. A decoder that gets an unexpected shape fails with a ReplyError.

Example (Defining a Command With an Integer Reply)

import {  } from "effect";

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

const :  = {
  : "CUSTOM.COUNT",
  : "custom",
  : "ordinary",
  : "never",
  : [{ : "https://example.com/custom-module", : "1.0.0" }],
  : ["custom-count"],
  : [],
};

const  = (: string) =>
  ({
    ,
    : ["CUSTOM.COUNT", ],
    : { : "Keys", : [{ : 1, : "read" }] },
    : Reply.,
  });

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

  const visits = yield* .(("visits"));
const visits: bigint
return ; });

routing tells a cluster client which arguments are keys. Use { _tag: "Keyless" } for a command with no key. replay is always "never": no command is sent again after a possible write.

Raw commands

redis.raw sends tokens as they are and returns the reply as a RespValue. You must pass a contract with the execution mode and routing. Without it the call does not compile.

Example (Sending Raw Tokens)

import {  } from "effect";

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

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

  const  = { : "ordinary", : { : "Keyless" } } as ;

  const reply = yield* .(["ECHO", "hello"], );
const reply: RespValue
return . === "BlobString" ? new ().(.) : ; });

Raw commands keep server errors as values. An error reply arrives as a RespValue with _tag: "SimpleError" and does not fail the Effect.