@lindorm-io/koa-redis
TypeScript icon, indicating that this package has built-in type declarations

0.8.12 • Public • Published

@lindorm-io/koa-redis

Mongo Connection middleware for @lindorm-io/koa applications

Installation

npm install --save @lindorm-io/koa-redis

Peer Dependencies

This package has the following peer dependencies:

Usage

Redis Connection Middleware

import { Redis } from "ioredis";
import { RedisConnection } from "@lindorm-io/redis";

const redisConnection = new RedisConnection({ ...options });

koaApp.addMiddleware(redisMiddleware(redisConnection));

await ctx.connection.redis.connect();

Cache Middleware

koaApp.addMiddleware(
  cacheMiddleware(YourCacheClass, {
    cacheKey: "key", // OPTIONAL [ string ]
    expiresInSeconds: 1000, // OPTIONAL [ number ]
  }),
);

await ctx.cache.yourCacheClass.create(yourEntity);

Entity Middleware

const middleware = cacheEntityMiddleware(YourEntityClass, YourCacheClass, {
  cacheKey: "key", // OPTIONAL [ string ]
  entityKey: "key", // OPTIONAL [ string ]
});

router.addMiddleware(
  middleware("body.entityName", {
    attributeKey: "name", // OPTIONAL [ string ]
    customValidation: async (context, entity) => {}, // OPTIONAL [ function ]
    optional: false, // OPTIONAL [ boolean ]
  }),
);

ctx.entity.yourEntityClass.id; // -> <uuid>

Readme

Keywords

none

Package Sidebar

Install

npm i @lindorm-io/koa-redis

Weekly Downloads

5

Version

0.8.12

License

AGPL-3.0-or-later

Unpacked Size

66.3 kB

Total Files

92

Last publish

Collaborators

  • princejonn