ratelimiter icon indicating copy to clipboard operation
ratelimiter copied to clipboard

Synchronize the rate limiter code

Open oscar-besga-panel opened this issue 3 months ago • 1 comments

In the file src/main/java/com/springboot/ratelimiter/user/service/impl/RateLimiterServiceImpl.java Make the part of the code that reads and updates the value on Redis synchronized. If not, many threads could access at the same time and read the same value, or update an old value that doesn't reflect the current situation.

oscar-besga-panel avatar Nov 06 '25 17:11 oscar-besga-panel

@oscar-besga-panel I think you can use stringRedisTemplate.opsForValue().increment(key) and define a bean in RedisConfig

@Bean
public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory cf) {
     return new StringRedisTemplate(cf);
}

If you can solve it, open a pull request and then it can be merged from my side.

Rapter1990 avatar Nov 06 '25 20:11 Rapter1990