Skip to content

Commit

Permalink
Merge pull request #17 from team-special-week/feature/runner
Browse files Browse the repository at this point in the history
[FIX] redis 접속 안됨
  • Loading branch information
bb2002 authored Aug 17, 2022
2 parents f3e309f + 9259af9 commit 78553e8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
6 changes: 3 additions & 3 deletions src/common/constants/policy.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ export const TEMPLATE_DIRECTORY = path.join(__dirname, '../../../', 'template');
export const LIFECYCLE_INTERVAL = 1000 * 10;

// redis 는 도커 컨테이너에 내장되어 있습니다.
export const REDIS_HOST = 'localhost';
export const REDIS_PORT = 6379;
export const REDIS_TTL = 0;
// export const REDIS_HOST = 'localhost';
// export const REDIS_PORT = 6379;
// export const REDIS_TTL = 0;
30 changes: 15 additions & 15 deletions src/libs/cache-db/cache-db.module.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { CacheModule, Global, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-redis-store';
import { CacheDBService } from './cache-db.service';
import {
REDIS_HOST,
REDIS_PORT,
REDIS_TTL,
} from '../../common/constants/policy.constant';
// import {
// REDIS_HOST,
// REDIS_PORT,
// REDIS_TTL,
// } from '../../common/constants/policy.constant';

export const cacheModule = CacheModule.registerAsync({
useFactory: async () => ({
store: redisStore,
host: REDIS_HOST,
port: `${REDIS_PORT}`,
ttl: REDIS_TTL,
auth_pass: '',
}),
});
// export const cacheModule = CacheModule.registerAsync({
// useFactory: async () => ({
// store: redisStore,
// host: REDIS_HOST,
// port: `${REDIS_PORT}`,
// ttl: REDIS_TTL,
// auth_pass: '',
// }),
// });

@Global()
@Module({
imports: [cacheModule],
// imports: [cacheModule],
providers: [CacheDBService],
exports: [CacheDBService],
})
Expand Down
57 changes: 28 additions & 29 deletions src/libs/cache-db/cache-db.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,33 @@ import { Cache } from 'cache-manager';

@Injectable()
export class CacheDBService {
constructor(
@Inject(CACHE_MANAGER)
private readonly cacheManager: Cache,
) {}
constructor() // @Inject(CACHE_MANAGER)
// private readonly cacheManager: Cache,
{}

async set<T>(key: string, value: T, ttl = -1) {
if (ttl === -1) {
return this.cacheManager.set(key, value);
} else {
return this.cacheManager.set(key, value, {
ttl,
});
}
}

async get<T>(key: string) {
return this.cacheManager.get<T>(key);
}

async getKeys() {
return this.cacheManager.store.keys();
}

async del(key: string) {
return this.cacheManager.del(key);
}

getCacheManager(): Cache {
return this.cacheManager;
}
// async set<T>(key: string, value: T, ttl = -1) {
// if (ttl === -1) {
// return this.cacheManager.set(key, value);
// } else {
// return this.cacheManager.set(key, value, {
// ttl,
// });
// }
// }
//
// async get<T>(key: string) {
// return this.cacheManager.get<T>(key);
// }
//
// async getKeys() {
// return this.cacheManager.store.keys();
// }
//
// async del(key: string) {
// return this.cacheManager.del(key);
// }
//
// getCacheManager(): Cache {
// return this.cacheManager;
// }
}

0 comments on commit 78553e8

Please sign in to comment.