@lindorm-io/koa-redis
v0.8.12
Published
Redis Connection middleware for @lindorm-io/koa applications
Downloads
94
Readme
@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>