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.