'Spring Data JPA Redis: Query by multiple values for same key? Query by Example using REGEX not supported

Please let me know if this has been asked before.

I have a requirement to do some advanced filtering on data that is stored in Redis cache. Imagine there are 2 dropdowns which have many values, and each one can have MULTIPLE SELECTIONS. Each dropdown represents a field on our POJO that is in Redis.

Let's call the entity Stock, and the dropdowns category, pricingOption, and company.

An example query would be to find all cached MyStock objects where category falls in regex expression (energy|materials|healthcare). I have written some code to create this regex from a Set of String. I was hoping there would be more support in Redis for querying by Example than there is. Typically you could use this solution:

// take input as sets of strings for different dropdown selections
// construct regex pattern for each set, and assign them to fields of new myStockExample object
// then...
var matcher = ExampleMatcher.matching().withStringMatcher(StringMatcher.REGEX);
var example = Example.of(myStockExample, matcher);
var results = repository.findAll(example);

How can I achieve a similar solution to this that is supported by String Data Redis? It needs to be efficient as the cache will grow very large.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source