0

Remodeling Redis structure as NoSQL for a find by value solution suggests to record a single key set object?

My initial problem as "find all keys by value" in Redis. And for my surprise, that's not possible as it sounds, or it not a good option considering Redis use.

Searching in SO, I found this question Find key by value the answer for it is a remodeling structure approach.

My scenario

I have keys which are random UUID generated in code which store a boolean value. The UUID represents an request-id for an application which will return the success of this request after being processed. Then my application will store this request-id until it's not processed - there are some republishing feature if a 2 minutes timeout no response occurs for this request-id.

So, the data stored in Redis seems like:

44f672a0-36da-4906-9fa0-d3ee0b0f1989 true
33749e7e-5e62-4340-8914-cb9f6eed6111 false
and so on...

In some point of my code I should find all keys not processed. Which is a problem with this structure, I should have to scan all keys and for each key find the associated value. It's like a 2 querying per key - not a good approach.

Solution scenario

So, according to this question and answer I should store a single key named false with a set of values which are my request-id. So it would looks like:

false [33749e7e-5e62-4340-8914-cb9f6eed6111, 36b1eb8f-1576-49e7-a95a-ab852cc2624d ...]

So here we solved the find by value problem. Since I just have a single key false I'll found all not keys not processed.

But now I have to update this set key all the time I receive a success processing request instead of deleting a single key.

Does this updating set scenario could be a performance problem?

The idea is not to have a large unprocessed request-id. This set aims to be small in size and values

I think this is a design problem not a driver or code problem, but I'm using Java with Jedis to communicate with Redis.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Guerino Rodella
  • 321
  • 4
  • 16
  • 2
    both `sadd` and `srem` works for o(1) for a single element - if you want this solution to be memory friendly - you may consider hash data type instead of strings for your boolean storage. Please check this link for memory optimization https://stackoverflow.com/questions/10004565/redis-10x-more-memory-usage-than-data/ – Ersoy May 07 '20 at 22:18
  • Great! So for performance improvement I should store them into a hashing mechanism. Could you provide a full example storing hash sets using Jedis? – Guerino Rodella May 08 '20 at 00:49
  • I am not familiar with java but, https://dzone.com/articles/3-ways-to-use-redis-hash-in-java this link explains it with different libraries. – Ersoy May 08 '20 at 06:52

0 Answers0