Skip to content

Commit

Permalink
fix: adjust close connection redis
Browse files Browse the repository at this point in the history
  • Loading branch information
William Koller committed Apr 27, 2022
1 parent 736191c commit 337712e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/modules/cache/cache.settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CacheModule as BaseCacheModule } from '@nestjs/common';
import { CachesRepository } from './repositories/caches.repository';
import * as redisStore from 'cache-manager-redis-store';

export const imports = [
BaseCacheModule.register({
store: redisStore,
url: process.env.REDIS_URL,
isGlobal: true,
}),
Expand Down
12 changes: 5 additions & 7 deletions src/modules/cache/repositories/caches.repository.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { GET_BOOKS_CACHE_KEY } from '@/modules/cache/constants/books-cache-key.constant';
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';

import { Cache } from 'cache-manager';

@Injectable()
export class CachesRepository {
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager) {
const client = cacheManager.store.getClient();
client.on('err', (err) => {
console.info(err);
});
}
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}

async clearCache(): Promise<void> {
const keys: string[] = await this.cacheManager.store.keys();

Expand All @@ -24,6 +22,6 @@ export class CachesRepository {
}

async getCache(name: string): Promise<number> {
return await this.cacheManager.get(name);
return await this.cacheManager.get<number>(name);
}
}

0 comments on commit 337712e

Please sign in to comment.