Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis TTL does not work #116

Closed
JakobStadlhuber opened this issue Jul 15, 2022 · 6 comments
Closed

Redis TTL does not work #116

JakobStadlhuber opened this issue Jul 15, 2022 · 6 comments
Milestone

Comments

@JakobStadlhuber
Copy link

JakobStadlhuber commented Jul 15, 2022

I use redis as a cache but I can't configure TTL on the redis level. I think it is because the naming in redis is different to what I configured it:

some of the Bucket4j configs:

bucket4j.enabled=true
bucket4j.cache-to-use=redis
bucket4j.filters[0].cache-name=bucket4j
bucket4j.filters[0].url=.*
bucket4j.filters[0].http-response-body={ "message": "Too many requests" }
#bucket4j.filters[0].rate-limits[0].expression=getRemoteAddr()
bucket4j.filters[0].rate-limits[0].bandwidths[0].capacity=2
bucket4j.filters[0].rate-limits[0].bandwidths[0].time=120
bucket4j.filters[0].rate-limits[0].bandwidths[0].unit=seconds
bucket4j.filters[0].rate-limits[0].bandwidths[1].capacity=50
bucket4j.filters[0].rate-limits[0].bandwidths[1].time=24
bucket4j.filters[0].rate-limits[0].bandwidths[1].unit=hours
...
spring.cache.cache-names=bucket4j

Redis:
Bildschirmfoto 2022-07-15 um 19 38 30

Cache TTL Setting:
@Configuration class RedisConfig { @Bean fun redisCacheManagerBuilderCustomizer(): RedisCacheManagerBuilderCustomizer { return RedisCacheManagerBuilderCustomizer { builder: RedisCacheManagerBuilder -> configurationMap["bucket4j"] = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofHours(48)) builder.withInitialCacheConfigurations(configurationMap) } } }

@leter
Copy link

leter commented Jul 16, 2022

can the author provide a configuration item in yml to set the keys ttl? because if you set ip address as key ,household ip addres will often change, when ip changed the previous ip were untouchable and finally turn to diry data.

@JakobStadlhuber
Copy link
Author

JakobStadlhuber commented Jul 16, 2022

I tried everything with spring.cache.redis.time-to-live=100 and also programmaticly I can't configure the TTL. I also use Redis for Caching different things, the TTL settings are there no problem the problem only exists with bucket4j. The problem also exists without bucket4j.filters[0].rate-limits[0].expression=getRemoteAddr()

@JakobStadlhuber
Copy link
Author

JakobStadlhuber commented Jul 16, 2022

The problem still exists when setting the default redis ttl globally, it is simply not used.

@MarcGiffing
Copy link
Owner

@ttulka You've added the Redis Support in this project and also add Support for Jedis in the Bucket4j project bucket4j/bucket4j#275. I haven't used Redis yet and I would be very thankful for your help. I even don't understand the real problem.

@MarcGiffing
Copy link
Owner

Oh, I've found this one:
bucket4j/bucket4j#279 (comment)

@ttulka
Copy link
Contributor

ttulka commented Sep 23, 2022

Oh, I've found this one: bucket4j/bucket4j#279 (comment)

Yes, I added Redis support to bucket4j, so the whole com.giffing.bucket4j.spring.boot.starter.config.cache.redis is obsolete.
A clash of those two implementations could simply cause the problem. I would recommend removing it from the starter whatsoever.

@MarcGiffing MarcGiffing added this to the 0.8.0 milestone Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants