ProxyManager issues with JedisConnectionFactory from spring-data-redis #426
-
Redisson with Bucket4j There are tons of tutorials our there to use bucket4j with redis. Almost all of them use redisson as client. They generally create a config & then using it create a CacheManager with a cache. Then they create a ProxyManager bean in which they pass that created cache using CacheManager bean. Following is the ProxyManager code which I guess is the relevant one for bucket4j
Here is one of the reference tutorial: https://www.freecodecamp.org/news/rate-limiting-with-bucket4j-and-redis/ Jedis with Bucket4j Then after much digging I have found some way to use Jedis with buckey4j. I fetch the already created JedisConnectionFactory bean ( which I am using for redis db, pub/sub ), get the jedis pool from it & create the JedisBasedProxyManager. Here is the code
Issue with JedisBasedProxyManager The issue is its not creating a hash in my redis cluster, what I want to do is some how use the cache created in RedisCacheManager bean in JedisBasedProxyManager or in any way create the hash in JedisBasedProxyManager. Here is the code where I am creating RedisCacheManager.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I do not recommend to work with Redis over JCache. This way is the infinite source of tricky problems.
What does it mean?
JedisPool pool can be created without hacks: // for standalone Redis
new JedisPooled(redisHost, redisPort) // for Redis Cluster
List<HostAndPort> shards = new ArrayList<>();
shards.add(new HostAndPort(redisHost1, redisPort));
shards.add(new HostAndPort(redisHost2, redisPort));
shards.add(new HostAndPort(redisHost3, redisPort));
...
shards.add(new HostAndPort(redisHosttN, redisPort));
return new JedisCluster(new HashSet<>(shards)); |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
But... Redis hash does not provide expiration for individual items in the hash, it makes impossible to expire buckets that became unused. Redisson integration had been initially written on top of Redisson/RMap that uses RedisHash behind, but then it was rewritten to use
Feel free to stay with Redis, but use one of direct Bucket4j integration with Jedis, Lettuce or Redisson. But if organizing multiple buckets in one collection is dominant requirement then I would recommend to switch to ApacheIgnite/Hazelcast/Infinispan. |
Beta Was this translation helpful? Give feedback.
But... Redis hash does not provide expiration for individual items in the hash, it makes impossible to expire buckets that became unused. Redisson integration had been initially written on top of Redisson/RMap that uses RedisHash behind, but then it was rewritten to use
org.redisson.command.CommandExecutor
in order to add TTL feature, you can see discussion there #161 (comment)Feel free to stay with Redis, but use one of direct Bucket4j integration with Jedis, Lettuce or Redisson. But if organizing multiple buckets in one collection is dominant requirement …