Skip to content

qoq-ts/qoq-redis

Repository files navigation

qoq-redis

redis for qoq based on ioredis.

License GitHub Workflow Status (branch) Codecov npm

Installation

yarn add qoq-redis

Create redis middleware

import { WebSlotManager, defineConfig } from 'qoq';
import { RedisSlot, RedisOptions } from 'qoq-redis';

const redisOptions = defineConfig<RedisOptions>({
  ...
});

const webSlots = WebSlotManager.use(new RedisSlot(redisOptions));

Then feel free to use in request or commands

import { createWebRouter } from 'qoq';

export const router = createWebRouter(webSlots);

router.get('/').action(async (ctx) => {
  await ctx.redis.set('hello', 'world');
  ctx.body = 'OK';
});

Create cache middleware

import { WebSlotManager, ConsoleSlotManager, defineConfig } from 'qoq';
import { Redis, RedisOptions } from 'qoq-redis';
+ import { CacheSlot } from 'qoq';
+ import { RedisCacheOptions } from 'qoq-redis';

const redisOptions = defineConfig<RedisOptions>({
  ...
});
+ const cacheOptions = defineConfig<RedisCacheOptions>({
+  engine: 'qoq-redis/RedisCache',
+  redisOptions: redisOptions,
+ });

const webSlots = WebSlotManager
  .use(new RedisSlot(redisOptions))
+ .use(new CacheSlot(cacheOptions));

Options

@see ioredis

Releases

No releases published

Packages

No packages published