17 lines
515 B
TypeScript
17 lines
515 B
TypeScript
import { createKeyv, KeyvRedisOptions } from '@keyv/redis';
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
import { parse, stringify } from 'flatted';
|
|
import { keyvConfig, KeyvConfig } from './keyv.config';
|
|
|
|
@Injectable()
|
|
export class KeyvService {
|
|
constructor(@Inject(keyvConfig.KEY) private readonly config: KeyvConfig) {}
|
|
|
|
create(options?: KeyvRedisOptions) {
|
|
const keyv = createKeyv(this.config.redis, options);
|
|
keyv.serialize = stringify;
|
|
keyv.deserialize = parse;
|
|
return keyv;
|
|
}
|
|
}
|