@level-two/redis
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

LevelTwo - Redis

A message broker and cache extension for LevelTwo. Refer to the Worker API for function definitions.

Usage

import { createLevelTwoRedis } from "@level-two/redis";

// Integrates redis pubsub & cache into a LevelTwo instance
const levelTwo = createLevelTwoRedis({
  clientOptions: { url: "redis://localhost:6379" },
});

// Create a worker for getting cacheable customer objects
const worker = levelTwo.createWorker("customer", async (ids, earlyWrite) => {
  const rows = await mysql.query(
    "SELECT id, name FROM customers WHERE id IN (?)",
    [ids]
  );

  rows.forEach((row) => earlyWrite(row.id, row));
});

// Service method for getting a single customer
export async function getCustomer(id: string): Promise<Customer> {
  return await worker.get(id);
}

// Service method for getting a list of customers
export async function getCustomerList(ids: string[]): Promise<Customer[]> {
  return await worker.getMulti(ids);
}

Settings

redis

Existing redis client that should be used in this extension

clientOptions

Configuration options for creating a new redis client

broadcastChannel

Broadcast channel name for sending/receiving actions. Defaults to "level-two-broadcast"

cachePrefix

String prefix to use in front of each cache key

cacheDisabled

Indicates if cache should be disabled or not. Defaults to enabled

cacheDefaults

LevelTwo worker cache defaults

/@level-two/redis/

    Package Sidebar

    Install

    npm i @level-two/redis

    Weekly Downloads

    0

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    30 kB

    Total Files

    20

    Last publish

    Collaborators

    • codenothing