Skip to content

API Overview

Most applications use three imports:

import { benni } from "benni";
import { node } from "benni/node";
import { hash, hll, json, kv, number, string, zset } from "benni/schema";

Use benni/schema to define Redis key families:

kv("profile", json<Profile>());
hash("user", { name: string(), score: number() });
set("team-members", string());
list("events", json<Event>());
zset("leaderboard", string());
hll("page-views", string());
channel("events:user", json<UserEvent>());

Bind a Redis client:

const redis = benni(client, { schema });

Use data-structure resources:

redis.kv(profiles);
redis.hash(users);
redis.set(teamMembers);
redis.list(events);
redis.zset(leaderboards);
redis.hll(pageViews);
redis.pubsub.channel(userEvents);

Use redis.raw for direct Redis commands:

await redis.raw.send(["PING"]);

The benni/core entrypoint exposes the building blocks the client is made of (defineKeyspace, createKeyValueStore, createHashStore, and the other store builders) for adapter authors and advanced integrations.

Application code should prefer the schema-first API shown in the guide; every accessor is documented in the Benni Client reference.