Mark
Mark

Reputation: 7635

Is Redis the right choice for this model

I am having a following model:

| string (unique key) | about 10 other strings, that have all a fixed length and may be empty |

On commonly query is using the 'unique key and see the other strings'. This should be fine using Redis.

But another query is 'show me the keys where column n is empty'. I am not sure if Redis can handle this performant!?

Upvotes: 0

Views: 161

Answers (1)

Mark Tozzi
Mark Tozzi

Reputation: 10953

To solve this in redis, you will need to maintain some meta data. One solution would be to add a set type key for each "column" that would hold the unique keys of all elements where that "column" is blank. Obviously, in your application logic, you will need to add and remove unique keys from these sets as you add and remove values in your main hash. This will be very fast, as the set operations sadd, srem and sismember are all O(1) for single items (i.e. not proportional to the size of the set). To get all keys where a "column" is empty, you can use smembers. At least, that's how I've solved similar problems.

(I put quotes around columns since in the redis model, they will be hash fields, not columns as you think of them in an RDBMS)

Upvotes: 1

Related Questions