From 5a6b87fcd04688f2acfd3ccbe15f4819ba5c0209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=80=E1=85=AA=E1=86=BC=E1=84=92?= =?UTF-8?q?=E1=85=AE=E1=86=AB?= Date: Sat, 9 Dec 2023 13:49:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[BE]=20Feat=20:=20Redis=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/package-lock.json | 110 +++++++++++++++++++++++++++++++++++++++++++ BE/package.json | 4 ++ BE/src/app.module.ts | 9 +++- 3 files changed, 121 insertions(+), 2 deletions(-) diff --git a/BE/package-lock.json b/BE/package-lock.json index 924113b..44c8a11 100644 --- a/BE/package-lock.json +++ b/BE/package-lock.json @@ -10,6 +10,7 @@ "license": "UNLICENSED", "dependencies": { "@aws-sdk/client-s3": "^3.454.0", + "@nestjs/cache-manager": "^2.1.1", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.0.0", @@ -20,6 +21,8 @@ "@nestjs/swagger": "^7.1.15", "@nestjs/typeorm": "^10.0.1", "@nestjs/websockets": "^10.2.10", + "cache-manager": "^5.3.1", + "cache-manager-ioredis": "^2.1.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "firebase-admin": "^11.11.1", @@ -41,6 +44,7 @@ "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.2.10", + "@types/cache-manager": "^4.0.6", "@types/express": "^4.17.17", "@types/jest": "^29.5.2", "@types/multer-s3": "^3.0.3", @@ -2585,6 +2589,18 @@ "node": ">=8" } }, + "node_modules/@nestjs/cache-manager": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@nestjs/cache-manager/-/cache-manager-2.1.1.tgz", + "integrity": "sha512-oYfRys4Ng0zp2HTUPNjH7gizf4vvG3PQZZ+3yGemb3xrF+p3JxDSK0cDq9NTjHzD5UmhjiyAftB9GkuL+t3r9g==", + "peerDependencies": { + "@nestjs/common": "^9.0.0 || ^10.0.0", + "@nestjs/core": "^9.0.0 || ^10.0.0", + "cache-manager": "<=5", + "reflect-metadata": "^0.1.12", + "rxjs": "^7.0.0" + } + }, "node_modules/@nestjs/cli": { "version": "10.2.1", "resolved": "https://registry.npmjs.org/@nestjs/cli/-/cli-10.2.1.tgz", @@ -3827,6 +3843,12 @@ "@types/node": "*" } }, + "node_modules/@types/cache-manager": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/@types/cache-manager/-/cache-manager-4.0.6.tgz", + "integrity": "sha512-8qL93MF05/xrzFm/LSPtzNEOE1eQF3VwGHAcQEylgp5hDSTe41jtFwbSYAPfyYcVa28y1vYSjIt0c1fLLUiC/Q==", + "dev": true + }, "node_modules/@types/connect": { "version": "3.4.38", "resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.38.tgz", @@ -5147,6 +5169,68 @@ "node": ">= 0.8" } }, + "node_modules/cache-manager": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/cache-manager/-/cache-manager-5.3.1.tgz", + "integrity": "sha512-9HP6nc1ZqyZgcVEpy5XS2ns9MYE6cPEM6InA1wQhR6M7GviJzLH2NTFYnf3NEfRmLE351NCSkDo2VISX8dlG+w==", + "dependencies": { + "lodash.clonedeep": "^4.5.0", + "lru-cache": "^10.0.2", + "promise-coalesce": "^1.1.1" + } + }, + "node_modules/cache-manager-ioredis": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cache-manager-ioredis/-/cache-manager-ioredis-2.1.0.tgz", + "integrity": "sha512-TCxbp9ceuFveTKWuNaCX8QjoC41rAlHen4s63u9Yd+iXlw3efYmimc/u935PKPxSdhkXpnMes4mxtK3/yb0L4g==", + "dependencies": { + "ioredis": "^4.14.1" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/cache-manager-ioredis/node_modules/denque": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", + "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", + "engines": { + "node": ">=0.10" + } + }, + "node_modules/cache-manager-ioredis/node_modules/ioredis": { + "version": "4.28.5", + "resolved": "https://registry.npmjs.org/ioredis/-/ioredis-4.28.5.tgz", + "integrity": "sha512-3GYo0GJtLqgNXj4YhrisLaNNvWSNwSS2wS4OELGfGxH8I69+XfNdnmV1AyN+ZqMh0i7eX+SWjrwFKDBDgfBC1A==", + "dependencies": { + "cluster-key-slot": "^1.1.0", + "debug": "^4.3.1", + "denque": "^1.1.0", + "lodash.defaults": "^4.2.0", + "lodash.flatten": "^4.4.0", + "lodash.isarguments": "^3.1.0", + "p-map": "^2.1.0", + "redis-commands": "1.7.0", + "redis-errors": "^1.2.0", + "redis-parser": "^3.0.0", + "standard-as-callback": "^2.1.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/ioredis" + } + }, + "node_modules/cache-manager/node_modules/lru-cache": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz", + "integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==", + "engines": { + "node": "14 || >=16.14" + } + }, "node_modules/call-bind": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.5.tgz", @@ -9176,6 +9260,11 @@ "resolved": "https://registry.npmjs.org/lodash.defaults/-/lodash.defaults-4.2.0.tgz", "integrity": "sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==" }, + "node_modules/lodash.flatten": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/lodash.flatten/-/lodash.flatten-4.4.0.tgz", + "integrity": "sha512-C5N2Z3DgnnKr0LOpv/hKCgKdb7ZZwafIrsesve6lmzvZIRZRGaZ/l6Q8+2W7NaT+ZwO3fFlSCzCzrDCFdJfZ4g==" + }, "node_modules/lodash.includes": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.includes/-/lodash.includes-4.3.0.tgz", @@ -9948,6 +10037,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/p-map": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-2.1.0.tgz", + "integrity": "sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==", + "engines": { + "node": ">=6" + } + }, "node_modules/p-try": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", @@ -10252,6 +10349,14 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, + "node_modules/promise-coalesce": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/promise-coalesce/-/promise-coalesce-1.1.1.tgz", + "integrity": "sha512-k7+VaIwZc5dRfSF6RELqRY1+LCmcCkrnuNV9HzIpA6iwRHKke+j9yb0LBTTHQ2RRgf6AlMl9TntuTzcgV/BZwg==", + "engines": { + "node": ">=18" + } + }, "node_modules/prompts": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", @@ -10603,6 +10708,11 @@ "node": ">= 0.10" } }, + "node_modules/redis-commands": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz", + "integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==" + }, "node_modules/redis-errors": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz", diff --git a/BE/package.json b/BE/package.json index 12c6d41..5d26d71 100644 --- a/BE/package.json +++ b/BE/package.json @@ -21,6 +21,7 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.454.0", + "@nestjs/cache-manager": "^2.1.1", "@nestjs/common": "^10.0.0", "@nestjs/config": "^3.1.1", "@nestjs/core": "^10.0.0", @@ -31,6 +32,8 @@ "@nestjs/swagger": "^7.1.15", "@nestjs/typeorm": "^10.0.1", "@nestjs/websockets": "^10.2.10", + "cache-manager": "^5.3.1", + "cache-manager-ioredis": "^2.1.0", "class-transformer": "^0.5.1", "class-validator": "^0.14.0", "firebase-admin": "^11.11.1", @@ -52,6 +55,7 @@ "@nestjs/cli": "^10.0.0", "@nestjs/schematics": "^10.0.0", "@nestjs/testing": "^10.2.10", + "@types/cache-manager": "^4.0.6", "@types/express": "^4.17.17", "@types/jest": "^29.5.2", "@types/multer-s3": "^3.0.3", diff --git a/BE/src/app.module.ts b/BE/src/app.module.ts index 372053f..8ac6da3 100644 --- a/BE/src/app.module.ts +++ b/BE/src/app.module.ts @@ -14,7 +14,8 @@ import { PostsBlockModule } from './posts-block/posts-block.module'; import { UsersBlockModule } from './users-block/users-block.module'; import { LoginModule } from './login/login.module'; import { ChatModule } from './chat/chat.module'; -import { RedisService } from './utils/redis'; +import { CacheModule } from '@nestjs/cache-manager'; +import * as redisStore from 'cache-manager-ioredis'; @Module({ imports: [ @@ -34,6 +35,11 @@ import { RedisService } from './utils/redis'; UsersModule, LoginModule, ChatModule, + CacheModule.register({ + store: redisStore, + host: process.env.REDIS_HOST, + port: process.env.REDIS_PORT, + }), ], controllers: [AppController], providers: [ @@ -43,7 +49,6 @@ import { RedisService } from './utils/redis'; provide: APP_PIPE, useClass: ValidationPipe, }, - //RedisService, ], }) export class AppModule {} From 854030aa7fbcb7cb25169f58c0dbe7d2b0d25a91 Mon Sep 17 00:00:00 2001 From: koomin1227 Date: Sat, 9 Dec 2023 14:47:02 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[BE]=20Feat=20:=20redis=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=ED=8C=8C=EC=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/app.module.ts | 10 ++++------ BE/src/config/redis.config.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 BE/src/config/redis.config.ts diff --git a/BE/src/app.module.ts b/BE/src/app.module.ts index 8ac6da3..6d13f6c 100644 --- a/BE/src/app.module.ts +++ b/BE/src/app.module.ts @@ -15,7 +15,7 @@ import { UsersBlockModule } from './users-block/users-block.module'; import { LoginModule } from './login/login.module'; import { ChatModule } from './chat/chat.module'; import { CacheModule } from '@nestjs/cache-manager'; -import * as redisStore from 'cache-manager-ioredis'; +import { RedisConfigProvider } from './config/redis.config'; @Module({ imports: [ @@ -29,17 +29,15 @@ import * as redisStore from 'cache-manager-ioredis'; TypeOrmModule.forRootAsync({ useClass: MysqlConfigProvider, }), + CacheModule.registerAsync({ + useClass: RedisConfigProvider, + }), PostsBlockModule, UsersBlockModule, PostModule, UsersModule, LoginModule, ChatModule, - CacheModule.register({ - store: redisStore, - host: process.env.REDIS_HOST, - port: process.env.REDIS_PORT, - }), ], controllers: [AppController], providers: [ diff --git a/BE/src/config/redis.config.ts b/BE/src/config/redis.config.ts new file mode 100644 index 0000000..5a05089 --- /dev/null +++ b/BE/src/config/redis.config.ts @@ -0,0 +1,13 @@ +import { CacheModuleOptions, CacheOptionsFactory } from '@nestjs/common/cache'; +import { ConfigService } from '@nestjs/config'; +import * as redisStore from 'cache-manager-ioredis'; +export class RedisConfigProvider implements CacheOptionsFactory { + configService = new ConfigService(); + createCacheOptions(): CacheModuleOptions { + return { + store: redisStore, + host: this.configService.get('REDIS_HOST'), + port: this.configService.get('REDIS_PORT'), + }; + } +}