qoq-redis
v0.0.9
Published
redis for qoq based on [ioredis](https://github.com/luin/ioredis).
Downloads
2
Readme
qoq-redis
redis for qoq based on ioredis.
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