2

I am writing a throttling logic where i need to throttle requests of a user if the total number of requests for that USERID reaches a threshold of 200 within a 2 hour time window(sliding window).

I need to insert a key with 2 hour timestamp in REDIS and increment the counter within that 2 hour window.

Example : For UserID = 123 and the current time is 02:14:08.288, for the next 2 hours that is upto 04:14:08.288 i need to fetch the key for the userID= 123 and increment counter, if the count reached 200, then i need to throttle the request. When the current time is 04:14:08.289, i need to reset the key/create a new key for the same userID.

How can this be done in JAVA / REDIS ?

Yathish Manjunath
  • 1,919
  • 1
  • 13
  • 23

0 Answers0