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

Strings

Look up the string commands on the Redis service, with their commands and reply types.

String commands read and write whole values, counters and byte ranges. The methods below are on the Redis service.

Example (Typing a Conditional Write and a Counter)

import {  } from "effect";

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

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

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

get returns Option<string> and getBytes returns Option<Uint8Array>. Counters return bigint. set returns void, a boolean when you pass a condition, and the previous value when you pass get: true.

Methods

MethodCommandReply typePurpose
redis.getGETOption<string>Read a key as UTF-8 text.
redis.getBytesGETOption<Uint8Array>Read a key as bytes.
redis.setSETSetResult<O>Write a value with an optional condition, expiry or previous-value read.
redis.setnxSETNXbooleanSet a key only if it does not exist.
redis.setexSETEXvoidSet a key with a time to live in seconds.
redis.psetexPSETEXvoidSet a key with a time to live in milliseconds.
redis.mgetMGETreadonly Option<Uint8Array>[]Read several keys in one command.
redis.msetMSETvoidWrite several keys.
redis.msetnxMSETNXbooleanWrite several keys only if none of them exist.
redis.msetexMSETEXbooleanWrite several keys with an optional condition and expiry.
redis.appendAPPENDbigintAppend to a value and return the new length.
redis.strlenSTRLENbigintReturn the length of a value in bytes.
redis.getdelGETDELOption<Uint8Array>Read a key and delete it.
redis.getsetGETSETOption<Uint8Array>Set a value and return the previous one.
redis.getexGETEXOption<Uint8Array>Read a key and change its expiry.
redis.getrangeGETRANGEUint8ArrayRead a slice of a value by offset.
redis.substrSUBSTRUint8ArrayRead a slice of a value by offset (older name for GETRANGE).
redis.setrangeSETRANGEbigintOverwrite part of a value from an offset.
redis.incrINCRbigintIncrement an integer value by one.
redis.incrbyINCRBYbigintIncrement an integer value by an amount.
redis.incrbyfloatINCRBYFLOATstringIncrement a value by a decimal amount; the result is the server's decimal text.
redis.decrDECRbigintDecrement an integer value by one.
redis.decrbyDECRBYbigintDecrement an integer value by an amount.
redis.increxINCREXreadonly [bigint, bigint]Increment an integer with optional bounds and expiry.
redis.increxFloatINCREXreadonly [string, string]Increment a decimal with optional bounds and expiry.
redis.lcsLCSUint8ArrayReturn the longest common subsequence of two values.
redis.lcsLengthLCSbigintReturn only the length of the longest common subsequence.
redis.lcsMatchesLCSLcsMatchesReturn the matching ranges of the longest common subsequence.
redis.digestDIGESTOption<Uint8Array>Return the digest of a string value.
redis.delifeqDELIFEQbooleanDelete a key if its value equals the given value.
redis.delexDELEXbooleanDelete a key, optionally under a value or digest condition.

SetOptions

redis.set takes SetOptions. The type of the options decides the reply type, as shown in SetResult. redis.setKey takes WriteSetOptions, which is SetOptions without get.

Prop

Type

expiryAfter(duration) turns an Effect Duration into an expiry value. It rejects durations shorter than one millisecond.

Example (Setting a Key With a Duration)

import { ,  } from "effect";

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

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

  const  = yield* (.(5));
  yield* .("session:abc", "user-42", {  });
});

IncrementExpiryOptions

redis.increx takes IncrementExpiryOptions. redis.increxFloat takes FloatIncrementExpiryOptions, where increment is required and values are number | string.

Prop

Type

Other option types

  • MultiSetOptions for redis.msetex: { condition?: "NX" | "XX"; expiry?: SetExpiry }.
  • DeleteCondition for redis.delex: { type: "IFEQ" | "IFNE" | "IFDEQ" | "IFDNE"; value: string | Uint8Array }.
  • Expiry for redis.getex: { type: "EX" | "PX" | "EXAT" | "PXAT"; value: number | bigint } | { type: "PERSIST" }.
  • LcsMatches is the redis.lcsMatches reply: { length: bigint; matches: ReadonlyArray<LcsMatch> }.

Typed keys

redis.getKey and redis.setKey read and write values through a RedisKey codec. See Typed values.

MethodCommandReply typePurpose
redis.getKeyGETOption<A>Read a key and decode it with the key's codec.
redis.setKeySETWriteSetResult<O>Encode a value with the key's codec and write it.