@@ -14,6 +14,8 @@ const TAKE_ELEVATED_LUA = fs.readFileSync(`${__dirname}/take_elevated.lua`, 'utf
1414const TAKE_EXPONENTIAL_LUA = fs . readFileSync ( `${ __dirname } /take_exponential.lua` , 'utf8' ) ;
1515const PUT_LUA = fs . readFileSync ( `${ __dirname } /put.lua` , 'utf8' ) ;
1616
17+ const BACKOFF_FACTOR_DEFAULT = 2 ;
18+ const MULTIPLE_UNIT_DEFAULT = 1000 ;
1719const DEFAULT_KEEPALIVE = 10000 ; // Milliseconds
1820
1921class LimitDBRedis extends EventEmitter {
@@ -270,31 +272,37 @@ class LimitDBRedis extends EventEmitter {
270272
271273 takeExponential ( params , callback ) {
272274 this . _doTake ( params , callback , ( key , bucketKeyConfig , count ) => {
275+ const useFixedWindow = isFixedWindowEnabled ( bucketKeyConfig . fixed_window , params . fixed_window ) ;
273276 this . redis . takeExponential ( key ,
274277 bucketKeyConfig . ms_per_interval || 0 ,
275278 bucketKeyConfig . size ,
276279 count ,
277280 Math . ceil ( bucketKeyConfig . ttl || this . globalTTL ) ,
278281 bucketKeyConfig . drip_interval || 0 ,
279- bucketKeyConfig . backoff_factor || 2 ,
280- bucketKeyConfig . multiple_unit || 1000 ,
282+ bucketKeyConfig . backoff_factor || BACKOFF_FACTOR_DEFAULT ,
283+ bucketKeyConfig . multiple_unit || MULTIPLE_UNIT_DEFAULT ,
284+ useFixedWindow ? bucketKeyConfig . interval : 0 ,
281285 ( err , results ) => {
282286 if ( err ) {
283287 return callback ( err ) ;
284288 }
285289 const remaining = parseInt ( results [ 0 ] , 10 ) ;
286290 const conformant = parseInt ( results [ 1 ] , 10 ) ? true : false ;
291+ const current_timestamp_ms = parseInt ( results [ 2 ] , 10 ) ;
287292 const reset = parseInt ( results [ 3 ] , 10 ) ;
288293 const backoff_factor = parseInt ( results [ 4 ] , 10 ) ;
289294 const backoff_time = parseInt ( results [ 5 ] , 10 ) ;
295+ const next_token_ms = parseInt ( results [ 6 ] , 10 ) ;
290296 const res = {
291297 conformant,
292298 remaining,
293299 reset : Math . ceil ( reset / 1000 ) ,
294300 limit : bucketKeyConfig . size ,
295301 delayed : false ,
296302 backoff_factor,
297- backoff_time
303+ backoff_time,
304+ delta_reset_ms : Math . max ( reset - current_timestamp_ms , 0 ) ,
305+ delta_backoff_time : next_token_ms - current_timestamp_ms ,
298306 } ;
299307 if ( bucketKeyConfig . skip_n_calls > 0 ) {
300308 this . callCounts . set ( key , { res, count : 0 } ) ;
0 commit comments