I'm using hash keys to store user details like:
hmset user:1 user_name lee age 21
hmset user:2 user_name david age 25
hmset user:3 user_name chris age 25
I need to search for users having age = 25
, name = lee
. How to do a search for a specified value in a given field?
You cannot. Redis is a key-value store, not a relational database.
In order to search for a specific data, you need to build an access path to this data. For instance, to get the users having age = 25, you need to build an index to map the age values to users. It can be done with a set. This is the same for the name.
Once you have sets for age and name, you can search users by intersecting the sets. For example:
Acually You can do it with put values in key
Now you can find them with "keys" command
Finally find specific hashes
All that I said is that you can do it in two steps put any number of values that you need in key then find them. But consider that it's not a good idea to put all values inside key Just put ones that you need to do filtering with. Cheers :)