skip to Main Content

I need to use two key values in Redis cache so that I can retrieve based on one Key? Kindly help on this,

Both keys would be string, and the value will be an entity where the key values will also be present.

Example:

: <compressed_json>

json structure:

    result{
         a{ 
           key: <something>
           b:<something>
           c:<something>
    } 
   }

I need to get value from redis, either by using key or by ‘b’, but i wouldn’t have both values at the same time.

2

Answers


  1. To implement the feature, it needs to build a simple Inverted index like below diagram, store your data as three parts.

    Index data with inverted index

    • Build two indexs for the two keys, the index is just a Redis String type, the key use the format like index:{key value}, the value is stored the key of the document that’s the JSON string.
    • The json string is also stored as Redis String type, key is Doc:{ID}, the ID can be dynamically generated, e.g. UUID/GUID.

    Get The Document by index (key 1 or key N)

    • Combine the value to index:{key value} format
    • Use the combined string key to call Redis retrieve the doc key
    • Use the doc key to call Redis retrieve the doc body.

    enter image description here

    Login or Signup to reply.
  2. Another solution would be to deploy RediSQL it will give you access to a fully functional SQL database, where you can query for both keys.

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