File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ const useRealRedis = !CI && NODE_ENV !== 'test' && !!REDIS_URL
1010const redisMaxDb = REDIS_MAX_DB || 15
1111
1212// Enable better stack traces in non-production environments
13- const redisOptions = {
13+ const redisBaseOptions = {
1414 showFriendlyErrorStack : NODE_ENV !== 'production'
1515}
1616
@@ -22,8 +22,10 @@ class RedisAccessor {
2222 )
2323 }
2424
25- const redisUrl = `${ REDIS_URL } /${ databaseNumber } `
26- const redisClient = useRealRedis ? new Redis ( redisUrl , redisOptions ) : new InMemoryRedis ( )
25+ const redisClient = useRealRedis
26+ ? new Redis ( REDIS_URL , { ...redisBaseOptions , db : databaseNumber } )
27+ : new InMemoryRedis ( )
28+
2729 this . _client = redisClient
2830
2931 this . _prefix = prefix ? prefix . replace ( / : + $ / , '' ) + ':' : ''
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ const Redis = require('ioredis')
55const isProduction = process . env . NODE_ENV === 'production'
66const { REDIS_URL } = process . env
77const rateLimitDatabaseNumber = 0
8- const redisUrl = `${ REDIS_URL } /${ rateLimitDatabaseNumber } `
98
109module . exports = rateLimit ( {
1110 // 1 minute (or practically unlimited outside of production)
@@ -16,5 +15,5 @@ module.exports = rateLimit({
1615 // Or anything with a status code less than 400
1716 skipSuccessfulRequests : true ,
1817 // When available, use Redis
19- store : REDIS_URL && new RedisStore ( { client : new Redis ( redisUrl ) } )
18+ store : REDIS_URL && new RedisStore ( { client : new Redis ( REDIS_URL , { db : rateLimitDatabaseNumber } ) } )
2019} )
You can’t perform that action at this time.
0 commit comments