Redis
Redis-backed keystore adapter.
Overview
- Redis-backed keystore storing each record in a Redis hash keyed by id.
- Maintains a secondary mapping from key hash to id for fast
findKeyByHash
.
Usage
import { createClient } from "redis";
import { RedisKeyStore, usefulkey } from "betterkey";
const client = createClient({ url: process.env.REDIS_URL });
await client.connect();
const keyStore = new RedisKeyStore(client, { keyPrefix: "usefulkey" });
const uk = usefulkey({ adapters: { keyStore } });
Options
Option | Type | Default | Description |
---|---|---|---|
keyPrefix | string | "usefulkey" | Namespace prefix for record and hash-to-id keys. |
Client compatibility
- Hash commands:
hSet
/hset
,hGetAll
/hgetall
- String commands:
get
,set
,del
Data model
- Key record hash at
"<keyPrefix>:key:<id>"
- Mapping
"<keyPrefix>:khash:<keyHash>"
→<id>