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

Streams

Look up the stream commands, consumer group commands and read option types.

Stream commands append entries to a log and read them back by ID or through consumer groups. These are the single-command forms. For continuous readers and acknowledged processing, use RedisStreams.

Example (Appending and Reading Entries)

import {  } from "effect";

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

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

  const id = yield* .("orders", "*", [
const id: `${bigint}-${bigint}`
["sku", "A-100"], ["qty", "2"], ]); const batch = yield* .([["orders", "0"]], { : 10 });
const batch: Option<readonly StreamRead<StreamEntry>[]>
return { , }; });

xadd returns the new entry ID as a ${bigint}-${bigint} template literal type. xread returns None when no stream has new entries.

Methods

MethodCommandReply typePurpose
redis.xaddXADD`${bigint}-${bigint}`Append an entry and return its ID.
redis.xaddIfExistsXADDOption<`${bigint}-${bigint}`>Append an entry only if the stream exists (NOMKSTREAM).
redis.xaddPayloadXADD`${bigint}-${bigint}`Append a single-field entry encoded with a StreamPayload codec.
redis.xlenXLENbigintReturn the number of entries.
redis.xrangeXRANGEreadonly StreamEntry[]Read entries between two IDs.
redis.xrevrangeXREVRANGEreadonly StreamEntry[]Read entries between two IDs, newest first.
redis.xdelXDELbigintDelete entries by ID.
redis.xdelexXDELEXreadonly (1n | -1n | 2n)[]Delete entries by ID with a reference policy.
redis.xtrimXTRIMbigintTrim a stream by length or minimum ID.
redis.xcfgsetXCFGSETvoidSet stream idempotency options.
redis.xreadXREADOption<readonly StreamRead<StreamEntry>[]>Read new entries without blocking.
redis.xreadgroupXREADGROUPOption<readonly StreamRead<GroupEntry>[]>Read entries for a consumer group without blocking.
redis.xreadgroupClaimXREADGROUPOption<readonly StreamRead<ClaimedGroupEntry>[]>Read for a consumer group and claim idle entries.
redis.xackXACKbigintAcknowledge entries for a group.
redis.xackdelXACKDELreadonly (1n | -1n | 2n)[]Acknowledge entries and delete them under a reference policy.
redis.xnackXNACKbigintNegatively acknowledge entries for a group.
redis.xgroupCreateXGROUP CREATEvoidCreate a consumer group.
redis.xgroupSetidXGROUP SETIDvoidMove a group's last delivered ID.
redis.xgroupDestroyXGROUP DESTROYbooleanDelete a consumer group.
redis.xgroupCreateconsumerXGROUP CREATECONSUMERbooleanCreate a consumer in a group.
redis.xgroupDelconsumerXGROUP DELCONSUMERbigintDelete a consumer and return its pending count.
redis.xgroupHelpXGROUP HELPreadonly string[]Return the XGROUP help text.
redis.xpendingXPENDINGPendingSummarySummarize a group's pending entries.
redis.xpendingEntriesXPENDINGreadonly PendingEntry[]List pending entries with owner and idle time.
redis.xclaimXCLAIMreadonly Option<GroupEntry>[]Claim pending entries for a consumer.
redis.xclaimIdsXCLAIMreadonly `${bigint}-${bigint}`[]Claim pending entries and return only their IDs.
redis.xautoclaimXAUTOCLAIMClaimPage<Option<GroupEntry>>Claim idle pending entries from a start ID.
redis.xautoclaimIdsXAUTOCLAIMClaimPage<`${bigint}-${bigint}`>Claim idle entries and return only their IDs.
redis.xinfoStreamXINFO STREAMStreamInfoReturn stream statistics.
redis.xinfoStreamFullXINFO STREAMStreamInfoFullReturn full stream, group and consumer detail (FULL).
redis.xinfoGroupsXINFO GROUPSreadonly StreamGroupInfo[]List consumer groups.
redis.xinfoConsumersXINFO CONSUMERSreadonly StreamConsumerInfo[]List a group's consumers.
redis.xinfoHelpXINFO HELPreadonly string[]Return the XINFO help text.

Blocking reads

Blocking commands need a session

redis.blpop and the other blocking commands do not exist on Redis. They hold a connection while they wait, so they live on RedisSessions and take BlockingOptions. See Sessions.

redis.xread and redis.xreadgroup accept StreamReadOptions without block. Reads that wait are on RedisSessions and take BlockingReadOptions or BlockingGroupOptions, which require block.

MethodCommandReply typePurpose
sessions.xreadBlockingXREADOption<readonly StreamRead<StreamEntry>[]>Read new entries, waiting up to the block time.
sessions.xreadgroupBlockingXREADGROUPOption<readonly StreamRead<GroupEntry>[]>Read for a consumer group, waiting up to the block time.
sessions.xreadgroupClaimBlockingXREADGROUPOption<readonly StreamRead<ClaimedGroupEntry>[]>Read for a group and claim idle entries, waiting up to the block time.

StreamReadOptions

xread takes ReadStreams, a non-empty tuple of [key, ReadId]. xreadgroup takes a group, a consumer and GroupReadStreams, a non-empty tuple of [key, GroupReadId]. ReadId is a StreamPosition, "$" or "+". GroupReadId is a StreamPosition or ">".

Prop

Type

GroupReadOptions has the same fields plus noAck?: boolean.

StreamAddOptions

xadd and xaddIfExists take an ID of the form "*", "<ms>-*" or "<ms>-<seq>" (AddId), a non-empty tuple of [field, value] pairs (StreamFieldInput), and StreamAddOptions.

Prop

Type

Group and claim options

  • GroupCreateOptions for xgroupCreate: { mkstream?: boolean; entriesRead?: number | bigint }. GroupSetIdOptions for xgroupSetid is the same without mkstream. GroupStart is a StreamPosition or "$".
  • PendingOptions for xpendingEntries: { start; end; count; idleMillis?; consumer? }.
  • ClaimOptions for xclaim: { deliveryTime?: { type: "IDLE" | "TIME"; millis }; retryCount?; force?; lastId? }.
  • AutoClaimOptions for xautoclaim: { count? }.
  • StreamNackOptions for xnack: { retryCount?; force? }. The mode argument is "SILENT" | "FAIL" | "FATAL".
  • StreamRangeOptions for xrange: { count? }. StreamConfigOptions for xcfgset: { idmpDurationSeconds?; idmpMaxSize? }.
  • StreamTrim for xtrim and ReferencePolicy as above. StreamIds is a non-empty tuple of StreamId.

Reply types

  • StreamEntry is { id: StreamId; fields: ReadonlyArray<readonly [Uint8Array, Uint8Array]> }.
  • GroupEntry is the same but fields is an Option, because a pending entry can outlive its payload.
  • ClaimedGroupEntry adds idleMillis and deliveries.
  • StreamRead<A> is { key: Uint8Array; entries: ReadonlyArray<A> }.
  • PendingSummary is { count; smallest; largest; consumers }. PendingEntry is { id; consumer; idleMillis; deliveries }.
  • ClaimPage<A> is { cursor; entries; deleted }.
  • StreamInfo, StreamInfoFull, StreamGroupInfo and StreamConsumerInfo are the XINFO replies.