File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ import { createClient , RedisClientOptions } from 'redis'
2+ import { Cache } from '../@types/cache'
3+
4+ export const getCacheConfig = ( ) : RedisClientOptions => ( {
5+ url : `redis://${ process . env . REDIS_USER } :${ process . env . REDIS_PASSWORD } @${ process . env . REDIS_HOST } :${ process . env . REDIS_PORT } ` ,
6+ password : process . env . REDIS_PASSWORD ,
7+ } )
8+
9+ export const getCacheClient = ( ) : Cache => {
10+ const config = getCacheConfig ( )
11+
12+ const client = createClient ( config )
13+
14+ return client
15+ }
Original file line number Diff line number Diff line change 1+ import { getCacheClient } from '../cache/client'
2+ import { ICacheAdapter } from '../@types/adapters'
3+ import { IRateLimiter } from '../@types/utils'
4+ import { RedisAdapter } from '../adapters/redis-adapter'
5+ import { SlidingWindowRateLimiter } from '../utils/sliding-window-rate-limiter'
6+
7+ let instance : IRateLimiter = undefined
8+
9+ export const slidingWindowRateLimiterFactory = ( ) => {
10+ if ( ! instance ) {
11+ const cache : ICacheAdapter = new RedisAdapter ( getCacheClient ( ) )
12+ instance = new SlidingWindowRateLimiter ( cache )
13+ }
14+
15+ return instance
16+ }
You can’t perform that action at this time.
0 commit comments