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

Keys and expiry

Look up the generic key commands, expiry commands and key scanning with their reply types.

Key commands work on any key regardless of its type: deleting, renaming, copying, sorting and setting expiry.

Example (Expiring and Inspecting a Key)

import {  } from "effect";

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

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

  yield* .("cache:report", "payload");

  const scheduled = yield* .("cache:report", 60);
const scheduled: boolean
const remaining = yield* .("cache:report");
const remaining: bigint
const removed = yield* .(["cache:report"]);
const removed: bigint
return { , , }; });

ttl returns -2n for a missing key and -1n for a key with no expiry. Other values are the remaining time in the method's unit.

Methods

MethodCommandReply typePurpose
redis.delDELbigintDelete keys and return how many existed.
redis.unlinkUNLINKbigintDelete keys and free their memory in the background.
redis.existsEXISTSbigintCount how many of the given keys exist.
redis.touchTOUCHbigintUpdate the last access time of keys.
redis.typeTYPEstringReturn the type name of a key.
redis.renameRENAMEvoidRename a key.
redis.renamenxRENAMENXbooleanRename a key only if the new name is free.
redis.copyCOPYbooleanCopy a key, optionally to another database.
redis.moveMOVEbooleanMove a key to another database.
redis.dumpDUMPOption<Uint8Array>Serialize a key.
redis.restoreRESTOREvoidCreate a key from a serialized value.
redis.randomkeyRANDOMKEYOption<Uint8Array>Return a random key.
redis.keysKEYSreadonly Uint8Array[]List keys matching a pattern in one command.
redis.scanSCANScanPage<Uint8Array>Read one cursor page of keys.
redis.sortSORTreadonly Option<Uint8Array>[]Sort a list, set or sorted set.
redis.sortRoSORT_ROreadonly Option<Uint8Array>[]Sort without writing, so it can run against replicas.
redis.sortStoreSORTbigintSort and store the result in a key.
redis.expireEXPIREbooleanSet an expiry in seconds.
redis.pexpirePEXPIREbooleanSet an expiry in milliseconds.
redis.expireatEXPIREATbooleanSet an expiry as a Unix time in seconds.
redis.pexpireatPEXPIREATbooleanSet an expiry as a Unix time in milliseconds.
redis.ttlTTLbigintRead the remaining time to live in seconds.
redis.pttlPTTLbigintRead the remaining time to live in milliseconds.
redis.expiretimeEXPIRETIMEbigintRead the expiry as a Unix time in seconds.
redis.pexpiretimePEXPIRETIMEbigintRead the expiry as a Unix time in milliseconds.
redis.persistPERSISTbooleanRemove an expiry.
redis.objectEncodingOBJECT ENCODINGOption<Uint8Array>Return the internal encoding of a key.
redis.objectFreqOBJECT FREQOption<bigint>Return the access frequency of a key.
redis.objectIdletimeOBJECT IDLETIMEOption<bigint>Return the seconds since a key was last accessed.
redis.objectRefcountOBJECT REFCOUNTOption<bigint>Return the reference count of a key.
redis.objectHelpOBJECT HELPreadonly string[]Return the OBJECT help text.

Option types

KeyExpireCondition for expire, pexpire, expireat and pexpireat is "NX" | "XX" | "GT" | "LT".

Prop

Type

That table is CopyOptions, used by copy. SortOptions is used by sort, sortRo and sortStore.

Prop

Type

RestoreOptions for restore is { replace?: boolean; absolute?: boolean; idleTime?: number | bigint; frequency?: number }.

Scanning keys

redis.scan reads one page. redis.scanKeys streams every key. Both take KeyScanOptions, which is ScanOptions plus type.

Prop

Type

redis.keys runs KEYS as one command against the whole keyspace. It is not a cursor and not a cluster helper. See Scanning for the stream form and Cluster scanning.