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

Sorted sets

Look up the sorted set commands, range types and blocking pops with their reply types.

Sorted set commands keep members ordered by score. Most score replies are the server's decimal text (string), so large and infinite values are not rounded.

Example (Ranking Players)

import {  } from "effect";

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

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

  yield* .("scores", [
    [120, "ada"],
    [95, "grace"],
    [140, "linus"],
  ]);

  const top = yield* .("scores", {
const top: readonly (readonly [Uint8Array<ArrayBufferLike>, string])[]
: "rank", : 0, : 1, : true, }); const rank = yield* .("scores", "ada");
const rank: Option<bigint>
const score = yield* .("scores", "ada");
const score: Option<number>
return { , , }; });

zscore returns Option<number>. Use zscoreToken to keep the decimal text.

Methods

MethodCommandReply typePurpose
redis.zaddZADDbigintAdd or update members with scores.
redis.zaddIncrementZADDOption<string>Add a score to one member (INCR) and return the new score.
redis.zincrbyZINCRBYstringIncrement a member's score.
redis.zremZREMbigintRemove members.
redis.zcardZCARDbigintCount the members.
redis.zcountZCOUNTbigintCount members within a score range.
redis.zlexcountZLEXCOUNTbigintCount members within a lexicographic range.
redis.zscoreZSCOREOption<number>Read a member's score as a number.
redis.zscoreTokenZSCOREOption<string>Read a member's score as the server's decimal text.
redis.zmscoreZMSCOREreadonly Option<string>[]Read several scores as decimal text.
redis.zrankZRANKOption<bigint>Return a member's rank, lowest score first.
redis.zrevrankZREVRANKOption<bigint>Return a member's rank, highest score first.
redis.zrankWithScoreZRANKOption<readonly [bigint, string]>Return a member's rank and score.
redis.zrevrankWithScoreZREVRANKOption<readonly [bigint, string]>Return a member's reverse rank and score.
redis.zrangeZRANGEreadonly Uint8Array[]Read members by rank, score or lexicographic range.
redis.zrangeWithScoresZRANGEreadonly (readonly [Uint8Array, string])[]Read members and scores by rank or score range.
redis.zrangestoreZRANGESTOREbigintStore a range of members in another key.
redis.zrevrangeZREVRANGEreadonly Uint8Array[]Read members by rank, highest first (older form).
redis.zrevrangeWithScoresZREVRANGEreadonly (readonly [Uint8Array, string])[]Read members and scores by rank, highest first.
redis.zrangebyscoreZRANGEBYSCOREreadonly Uint8Array[]Read members by score range (older form).
redis.zrangebyscoreWithScoresZRANGEBYSCOREreadonly (readonly [Uint8Array, string])[]Read members and scores by score range.
redis.zrevrangebyscoreZREVRANGEBYSCOREreadonly Uint8Array[]Read members by score range, highest first.
redis.zrevrangebyscoreWithScoresZREVRANGEBYSCOREreadonly (readonly [Uint8Array, string])[]Read members and scores by score range, highest first.
redis.zrangebylexZRANGEBYLEXreadonly Uint8Array[]Read members by lexicographic range (older form).
redis.zrevrangebylexZREVRANGEBYLEXreadonly Uint8Array[]Read members by lexicographic range, reversed.
redis.zremrangebyrankZREMRANGEBYRANKbigintRemove members by rank range.
redis.zremrangebyscoreZREMRANGEBYSCOREbigintRemove members by score range.
redis.zremrangebylexZREMRANGEBYLEXbigintRemove members by lexicographic range.
redis.zpopminZPOPMINreadonly (readonly [Uint8Array, string])[]Remove and return the lowest-scored members.
redis.zpopmaxZPOPMAXreadonly (readonly [Uint8Array, string])[]Remove and return the highest-scored members.
redis.zmpopZMPOPOption<readonly [Uint8Array, readonly (readonly [Uint8Array, string])[]]>Pop members from the first non-empty sorted set.
redis.zrandmemberZRANDMEMBEROption<Uint8Array>Return one random member.
redis.zrandmemberCountZRANDMEMBERreadonly Uint8Array[]Return several random members.
redis.zrandmemberWithScoresZRANDMEMBERreadonly (readonly [Uint8Array, string])[]Return several random members with scores.
redis.zinterZINTERreadonly Uint8Array[]Return the intersection of sorted sets.
redis.zinterWithScoresZINTERreadonly (readonly [Uint8Array, string])[]Return the intersection with scores.
redis.zinterstoreZINTERSTOREbigintStore the intersection in a key.
redis.zintercardZINTERCARDbigintCount the intersection, with an optional limit.
redis.zunionZUNIONreadonly Uint8Array[]Return the union of sorted sets.
redis.zunionWithScoresZUNIONreadonly (readonly [Uint8Array, string])[]Return the union with scores.
redis.zunionstoreZUNIONSTOREbigintStore the union in a key.
redis.zdiffZDIFFreadonly Uint8Array[]Return the difference of sorted sets.
redis.zdiffWithScoresZDIFFreadonly (readonly [Uint8Array, string])[]Return the difference with scores.
redis.zdiffstoreZDIFFSTOREbigintStore the difference in a key.
redis.zscanZSCANScanPage<readonly [Uint8Array, string]>Read one cursor page of members and scores.
redis.zscanMembersZSCANScanPage<Uint8Array>Read one cursor page of members only (NOSCORES).

SortedRange

zrange, zrangeWithScores and zrangestore take a SortedRange, a union tagged by by. zrangeWithScores takes SortedRangeWithScores, which excludes by: "lex".

Prop

Type

  • Score is number | string.
  • ScoreBound is a Score or { exclusive: Score }.
  • LexBound is "-", "+" or { value: RedisArgument; exclusive?: boolean }.
  • RangeLimit is { offset; count }.

SortedAddOptions

zadd and zaddIncrement take SortedAddOptions. zadd takes ScoredMembers, a non-empty tuple of [score, member] pairs.

Prop

Type

SortedAlgebraOptions

zinter, zunion and their store variants take SortedAlgebraOptions.

Prop

Type

Blocking commands

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.

MethodCommandReply typePurpose
sessions.bzpopminBZPOPMINOption<readonly [Uint8Array, Uint8Array, string]>Pop the lowest-scored member, waiting if all sets are empty.
sessions.bzpopmaxBZPOPMAXOption<readonly [Uint8Array, Uint8Array, string]>Pop the highest-scored member, waiting if all sets are empty.
sessions.bzmpopBZMPOPOption<readonly [Uint8Array, readonly (readonly [Uint8Array, string])[]]>Pop members from the first non-empty sorted set, waiting if all are empty.

redis.zscan takes a cursor and ScanOptions and returns a ScanPage<readonly [Uint8Array, string]>. redis.zscanMembers sends NOSCORES, which is a Valkey option, so other servers can return a ServerError. redis.scanSortedSet and redis.scanSortedMembers stream the whole set. See Scanning.