File tree Expand file tree Collapse file tree 9 files changed +144
-7
lines changed Expand file tree Collapse file tree 9 files changed +144
-7
lines changed Original file line number Diff line number Diff line change 1
1
# get yours @ https://api.golemio.cz/api-keys/auth/sign-up
2
2
GOLEMIO_API_KEY=
3
3
4
-
4
+ # postgres
5
5
POSTGRES_USER=pg_user
6
6
POSTGRES_PASSWORD=pg_password
7
7
POSTGRES_DB=metro-now
@@ -11,6 +11,11 @@ DB_HOST=host.docker.internal
11
11
DB_PORT=5432
12
12
DB_SCHEMA=public
13
13
14
+
15
+ # redis
16
+ REDIS_HOST=host.docker.internal
17
+ REDIS_PORT=6379
18
+
14
19
# This was inserted by `prisma init`:
15
20
# Environment variables declared in this file are automatically made available to Prisma.
16
21
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
Original file line number Diff line number Diff line change 1
1
# get yours @ https://api.golemio.cz/api-keys/auth/sign-up
2
2
GOLEMIO_API_KEY=
3
3
4
-
4
+ # postgres
5
5
POSTGRES_USER=pg_user
6
6
POSTGRES_PASSWORD=pg_password
7
7
POSTGRES_DB=metro-now
@@ -21,3 +21,6 @@ DB_SCHEMA=public
21
21
22
22
DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}?schema=${DB_SCHEMA}"
23
23
24
+ # redis
25
+ REDIS_HOST=localhost
26
+ REDIS_PORT=6379
Original file line number Diff line number Diff line change 35
35
"@nestjs/swagger" : " ^7.4.2" ,
36
36
"@prisma/client" : " 5.20.0" ,
37
37
"cache-manager" : " ^5.7.6" ,
38
+ "cache-manager-redis-yet" : " ^5.1.5" ,
38
39
"graphql" : " ^16.9.0" ,
39
40
"radash" : " ^12.1.0" ,
40
41
"reflect-metadata" : " ^0.2.2" ,
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ import { StopModule } from "src/modules/stop/stop.module";
25
25
LoggerModule ,
26
26
ConfigModule . forRoot ( configModuleConfig ) ,
27
27
ScheduleModule . forRoot ( ) ,
28
- CacheModule . register ( cacheModuleConfig ) ,
28
+ CacheModule . registerAsync ( cacheModuleConfig ) ,
29
29
GraphQLModule . forRoot < ApolloDriverConfig > ( {
30
30
driver : ApolloDriver ,
31
31
playground : true ,
Original file line number Diff line number Diff line change 1
- import type { CacheModuleOptions } from "@nestjs/cache-manager" ;
1
+ import type { CacheModuleAsyncOptions } from "@nestjs/cache-manager" ;
2
+ import { redisStore } from "cache-manager-redis-yet" ;
2
3
3
- export const cacheModuleConfig : CacheModuleOptions = {
4
+ export const cacheModuleConfig : CacheModuleAsyncOptions = {
4
5
isGlobal : true ,
6
+ useFactory : async ( ) => ( {
7
+ store : await redisStore ( {
8
+ socket : {
9
+ host : process . env . REDIS_HOST || "localhost" ,
10
+ port : parseInt ( process . env . REDIS_PORT || "6379" ) ,
11
+ } ,
12
+ } ) ,
13
+ max : 1_000 ,
14
+ } ) ,
5
15
} ;
Original file line number Diff line number Diff line change @@ -8,5 +8,9 @@ export const envSchema = z.object({
8
8
DB_HOST : z . string ( ) ,
9
9
DB_PORT : z . coerce . number ( ) . int ( ) . positive ( ) ,
10
10
DB_SCHEMA : z . string ( ) ,
11
+ REDIS_PORT : z . coerce . number ( ) . int ( ) . positive ( ) . optional ( ) ,
12
+ REDIS_HOST : z . string ( ) . optional ( ) ,
11
13
PORT : z . coerce . number ( ) . int ( ) . positive ( ) . optional ( ) ,
12
14
} ) ;
15
+
16
+ export type EnvSchema = z . infer < typeof envSchema > ;
Original file line number Diff line number Diff line change @@ -19,12 +19,22 @@ services:
19
19
timeout : 5s
20
20
retries : 5
21
21
22
+ redis-stack :
23
+ image : redis/redis-stack:latest
24
+ container_name : redis-stack
25
+ restart : always
26
+ ports :
27
+ - 6379:6379
28
+ - 8001:8001
29
+ extra_hosts :
30
+ - " host.docker.internal:host-gateway"
31
+
22
32
postgres :
23
33
container_name : postgres
24
34
image : postgres:16-alpine
25
35
restart : always
26
36
ports :
27
- - 5432:${POSTGRES_PORT:- 5432}
37
+ - 5432:5432
28
38
volumes :
29
39
- postgres-data:/var/lib/postgresql/data/
30
40
env_file :
@@ -44,6 +54,7 @@ services:
44
54
pnpm start:prod
45
55
depends_on :
46
56
- postgres
57
+ - redis-stack
47
58
build :
48
59
context : .
49
60
dockerfile : ./Dockerfile
Original file line number Diff line number Diff line change 11
11
"precommit" : " pnpm format" ,
12
12
"format" : " pnpm -r format && pnpm exec prettier . --write" ,
13
13
"format:check" : " pnpm -r format:check && pnpm exec prettier . --check" ,
14
- "docker:db:up " : " docker compose up postgres" ,
14
+ "docker:up:dev " : " docker compose up postgres redis-stack " ,
15
15
"docker:up" : " docker compose up -d --build" ,
16
16
"docker:down" : " docker compose down --remove-orphans --volumes"
17
17
},
You can’t perform that action at this time.
0 commit comments