Last active
April 20, 2022 22:28
-
-
Save reevik/9ad4961f2b0f3c93f794b60aa3c3ff5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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