Skip to content

Worked Examples

These examples show Benni as application Redis code, not isolated method calls.

import { hash, json, kv, number, string } from "benni/schema";
export const users = hash("user", {
name: string(),
score: number()
});
export const profiles = kv(
"profile",
json<{
bio: string;
links: string[];
}>()
);
await redis.hash(users).hset("42", {
name: "Ada",
score: 10
});
await redis.kv(profiles).set("42", {
bio: "First programmer",
links: ["https://example.com"]
});
import { boolean, kv } from "benni/schema";
export const flags = kv("feature-flag", boolean());
await redis.kv(flags).set("new-dashboard", true);
if (await redis.kv(flags).get("new-dashboard")) {
// enable the feature
}
const key = redis.hash(users).key("42");
const exists = await redis.raw.send(["EXISTS", key]);

For a copy-pasteable example of every data structure in turn, see Examples. The lower-level store builders live under benni/core; see the API Overview.