Skip to content

Instantly share code, notes, and snippets.

@reevik
Last active April 20, 2022 22:28
Show Gist options
  • Save reevik/9ad4961f2b0f3c93f794b60aa3c3ff5e to your computer and use it in GitHub Desktop.
Save reevik/9ad4961f2b0f3c93f794b60aa3c3ff5e to your computer and use it in GitHub Desktop.
public class RateLimiter {
private final RedissonBasedProxyManager redissonBasedProxyManager;
private final BucketConfiguration bucketConfiguration;
public RateLimiter(RedissonBasedProxyManager redissonBasedProxyManager,
BucketConfiguration bucketConfiguration) {
this.redissonBasedProxyManager = redissonBasedProxyManager;
this.bucketConfiguration = bucketConfiguration;
}
public boolean tryAccess(String key) {
return redissonBasedProxyManager
.builder()
.build(key, bucketConfiguration)
.tryConsume(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment