ratelimiter
ratelimiter copied to clipboard
Synchronize the rate limiter code
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
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.