Redis find key based on set value

redis

Solution

You have to maintain reverse indexes yourself. Along with those keys that you posted, you should create reverse references.

tag:python => [1]
tag:ruby => [1]
tag:rails => [1]

tag:fiction => [2, 3]
tag:fantasy => [2]
tag:adventure => [3]

Then it's trivial to do what you want. But maybe you should consider using another tool for the job. For example, MongoDB can efficiently index and query arrays.

Problem

Im using redis to store tags for certain entities. Examples of the data: ``` +-------------+--------------------------------+ | key | value | +-------------+--------------------------------+ | book:1:tags | [python, ruby, rails] | +-------------+--------------------------------+ | book:2:tags | [fiction, fantasy] | +-------------+--------------------------------+ | book:3:tags | [fiction, adventure] | +-------------+--------------------------------+ ``` How do I find all books with a particular tag, ie all books tagged with `fiction`?

Original source