Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis Support on Secondary index

Tags:

redis

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.

like image 397
Shikhil Gupta Avatar asked Oct 26 '25 18:10

Shikhil Gupta


2 Answers

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]"
like image 172
Guy Korland Avatar answered Oct 29 '25 13:10

Guy Korland


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

like image 32
MD Ruhul Amin Avatar answered Oct 29 '25 14:10

MD Ruhul Amin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!