skip to Main Content

I am using redis as database. Here is the example of key and value I am using. Both key and value are of type string.
Key – shipping_rate:64:MNR:Home-Delivery. It is combination of 3 fields like item_id (64), item_type (MNR) , delivery service (Home-Delivery). And I am appending service name (shipping_rate) before the key.

The values is a json string – {"PRD_CAT_NAME" : "PTO PARTS", "SHIPMENT_CHG" : "20.9", "ITEM_CHG" : "12.99", "CONSOLIDATION" : "N", "AREA_UPCHARGE" : "0", "MISC_UPCHARGE" : "0", "ACTIVE_FLAG" : "Y"}’

Now I want to get all the keys using the pattern like shipping_rate:64:MNR:*. Here my searching is based on the pattern only because that is the requirement. I am using the SCAN for searching. In my spring boot java code I am using ScanOptions. Then want to query redis db for the list of keys I get from the SCAN operation.

Now I want to know for this scenario is there any other better solution approach than SCAN?

I was looking for secondary indexing but is it a good idea to add secondary indexing on the key? And even if it is possible and I keep all the keys in a set (for indexing) then also I need to use pattern to search from the set and that is not possible because SMEMBERS does not work for pattern searching.

If scan is the only approach for this scenario and if my redis DB has 50 million record then how would be performance of SCAN? is there any metrics anyone aware of for this scenario

2

Answers


  1. Instead of using strings containing JSONs, consider using JSON keys. You can then index your JSON keys and use Redis Query Engine to search for specific keys based on their content instead of their name.

    Login or Signup to reply.
  2. An alternative to SCAN for key pattern searches in databases like Redis is the KEYS command, which can quickly return all keys matching a specific pattern. However, KEYS is not recommended for large datasets due to performance issues, as it blocks the database while searching. Another option is SSCAN, which works well with sets and allows for more efficient, incremental searches. You could also consider using ZSCAN for sorted sets or HSCAN for hash fields, depending on the data structure in use. These commands provide non-blocking, scalable searches over large datasets.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search