Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finwise-miniapp-be
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ThinhNC
finwise-miniapp-be
Commits
577ff7fe
Commit
577ff7fe
authored
Aug 29, 2026
by
ThinhNC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(infra): support REDIS_URL connection string and TLS for cloud Redis
parent
97360cba
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
20 deletions
+65
-20
.env.example
.env.example
+1
-0
cache.service.ts
src/common/services/cache.service.ts
+27
-17
env.config.ts
src/config/env.config.ts
+35
-3
webhook-queue.service.ts
src/modules/webhooks/webhook-queue.service.ts
+2
-0
No files found.
.env.example
View file @
577ff7fe
...
...
@@ -13,6 +13,7 @@ JWT_REFRESH_SECRET=change_me_refresh_secret
JWT_ACCESS_EXPIRES_IN=1d
JWT_REFRESH_EXPIRES_IN=7d
REDIS_URL=redis://red-d2xxxxxxxxxxxxxxxxxx:6379
REDIS_HOST=localhost
REDIS_PORT=7379
REDIS_PASSWORD=
...
...
src/common/services/cache.service.ts
View file @
577ff7fe
...
...
@@ -28,23 +28,33 @@ export class CacheService {
private
initRedis
()
{
try
{
this
.
redis
=
new
Redis
({
host
:
envConfig
.
redis
.
host
,
port
:
envConfig
.
redis
.
port
,
password
:
envConfig
.
redis
.
password
,
lazyConnect
:
true
,
maxRetriesPerRequest
:
3
,
retryStrategy
:
(
times
)
=>
{
if
(
times
>
3
)
{
this
.
logger
.
warn
(
'Failed to connect to Redis. Falling back to in-memory cache.'
);
this
.
isRedisConnected
=
false
;
this
.
redis
?.
disconnect
();
this
.
initMemoryCleanup
();
return
null
;
// Stop retrying
}
return
Math
.
min
(
times
*
100
,
2000
);
},
});
const
retryStrategy
=
(
times
:
number
)
=>
{
if
(
times
>
3
)
{
this
.
logger
.
warn
(
'Failed to connect to Redis. Falling back to in-memory cache.'
);
this
.
isRedisConnected
=
false
;
this
.
redis
?.
disconnect
();
this
.
initMemoryCleanup
();
return
null
;
}
return
Math
.
min
(
times
*
100
,
2000
);
};
if
(
envConfig
.
redis
.
url
)
{
this
.
redis
=
new
Redis
(
envConfig
.
redis
.
url
,
{
lazyConnect
:
true
,
maxRetriesPerRequest
:
3
,
retryStrategy
,
});
}
else
{
this
.
redis
=
new
Redis
({
host
:
envConfig
.
redis
.
host
,
port
:
envConfig
.
redis
.
port
,
password
:
envConfig
.
redis
.
password
,
lazyConnect
:
true
,
maxRetriesPerRequest
:
3
,
retryStrategy
,
});
}
this
.
redis
.
on
(
'connect'
,
()
=>
{
this
.
logger
.
info
(
'Successfully connected to Redis.'
);
...
...
src/config/env.config.ts
View file @
577ff7fe
...
...
@@ -150,9 +150,41 @@ export const envConfig = {
},
},
redis
:
{
host
:
process
.
env
.
REDIS_HOST
||
'localhost'
,
port
:
parseInt
(
process
.
env
.
REDIS_PORT
||
'6379'
,
10
),
password
:
process
.
env
.
REDIS_PASSWORD
||
undefined
,
url
:
process
.
env
.
REDIS_URL
||
''
,
host
:
(()
=>
{
if
(
process
.
env
.
REDIS_HOST
)
return
process
.
env
.
REDIS_HOST
;
if
(
process
.
env
.
REDIS_URL
)
{
try
{
return
new
URL
(
process
.
env
.
REDIS_URL
).
hostname
||
'localhost'
;
}
catch
{
return
'localhost'
;
}
}
return
'localhost'
;
})(),
port
:
(()
=>
{
if
(
process
.
env
.
REDIS_PORT
)
return
parseInt
(
process
.
env
.
REDIS_PORT
,
10
);
if
(
process
.
env
.
REDIS_URL
)
{
try
{
const
p
=
new
URL
(
process
.
env
.
REDIS_URL
).
port
;
return
p
?
parseInt
(
p
,
10
)
:
6379
;
}
catch
{
return
6379
;
}
}
return
6379
;
})(),
password
:
(()
=>
{
if
(
process
.
env
.
REDIS_PASSWORD
)
return
process
.
env
.
REDIS_PASSWORD
;
if
(
process
.
env
.
REDIS_URL
)
{
try
{
return
new
URL
(
process
.
env
.
REDIS_URL
).
password
||
undefined
;
}
catch
{
return
undefined
;
}
}
return
undefined
;
})(),
enabled
:
process
.
env
.
REDIS_ENABLED
!==
'false'
,
},
rateLimit
:
{
...
...
src/modules/webhooks/webhook-queue.service.ts
View file @
577ff7fe
...
...
@@ -38,10 +38,12 @@ export class WebhookQueueService {
return
;
}
const
isTls
=
envConfig
.
redis
.
url
.
startsWith
(
'rediss://'
);
const
connection
=
{
host
:
redisHost
,
port
:
redisPort
,
password
:
redisPassword
,
tls
:
isTls
?
{}
:
undefined
,
maxRetriesPerRequest
:
null
,
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment