Hello!
I am working on a technical solution which will use Redis Cluster as cache and I am using Lettuce as the Java client. I implemented straightforward all the basic functionalities (get, put etc) corresponding to specific needs of the product.
I am searching for an optimal solution for the problem of eviction/deletion of selective data (keys matching a pattern) from Redis Cluster. The reasoning behind it is the need for eviction when certain product properties are changing so I should be able to trigger periodically controlled evictions for different parts of data.
What I investigated so far:
1. Following the suggestions of Mark (
Iteration) I implemented a Scan method which iterates over the whole cluster and finds the matching keys which are deleted after. Tests: Redis cluster on Windows (3 master, 3 slaves), 80000 keys selected by specific pattern and deleted in 8 - 9 seconds. No tests over this limit due to technical limitations. It is unclear the speed for large quantities of data
2. Because of Redis cluster restrictions on different commands (like Eval of Lua scripts) I tested tags for keys. By using the tagging process you could force all related keys to be resolved in the same hash slot (keys with specific tag would live in a slot but unfortunately others can live there as well). The tests were much faster in speed than for the first solution in similar conditions.
Several downsides: the cluster would be unbalanced and failure of a node containing a lot of populated slots would be quite severe; several tags can fit in the same hash slot and we would have abnormal traffic on just some parts of the cluster
3. We can expire the required keys by setting corresponding TTLs but this would require an iteration on keys for a pattern and we are back to solution 1
4. Add keys that should be deleted together to a hash/list/set and delete them at once, as one object.
5. Flush all the content and regenerate all at once (not really a solution but still)
I would appreciate any feedback about the solutions and how to improve the speed.
Regards,
Catalin
PS. Very interesting article about RC and its current upgrade limitations:
Testable