Does redis provide support for secondary index on string data type?
I have installed redis server to check that, but could not find out clearly to do this.
I would like to know how i can store the data in redis along with seconday key.
Example let say i want to store thevehicle id:- registration no, in my case this will be primary key, vehicle color:- Red, this could be secondary key and payload related to vehicle info is my value. Now, I also want to find all payload whose color is red in redis.
Same as like i can do in MySql like
Select * from table where secondarycolumn="red"
Also, I would like to know while setting value in redis using primary key, how can i set the secondary index value for it.
You can easily add support for secondary index in Redis by deploying the RediSearch.
RediSearch supports defining automatic indexing of the hash fields and then to easily query those indexes using a simple query phrase.
e.g
FT.SEARCH myIdx "@name:Joe @age:[70-90]"
For secondary index you can use Hash data type. eg:
to store:
HSET myindex akash Manuel
To get:
HGET myindex akash
this will return: Manuel
check this link: Redis Hash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With