How do I ensure a bucket is created? #457
-
Hi, I'm currently utilizing Bucket4j backed by Redisson. Instead of using Spring Boot, I'm leveraging Spring solely for Dependency Injection, not integrating with Spring-data-redis or similar frameworks for bucket4j integration. I've configured a bucket featuring a Bandwidth parameter set with The code snippet below illustrates how I created the bucket: I create the bucket with the code similar to the following code: BucketConfiguration bucketConfig = myBucketConfigBuild();
Bucket bucket = proxyManager.builder().build(key, () -> configuration);
createMyInstanceWithBucket(bucket.asBlocking()); Upon debugging, I noticed that Bucket4j doesn't seem to generate a Redis key for the bucket until an action is performed on the bucket. As a workaround, I've been using consume(1) immediately after the bucket's creation. This approach serves as a check to ensure the bucket's existence, especially vital when multiple instances attempt to create the same bucket concurrently during deployment. I'm curious to know: Is there a more elegant method to instantiate the actual bucket key in Redis without the need to call consume(1)? btw, thank you for this amazing lib 🤗 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hello @Jaysok |
Beta Was this translation helpful? Give feedback.
Hello @Jaysok
Use getAvailableTokens