0

I have created Redis hash and stored below entries - 101- 104 are the hash keys

HMSET 101 field1 101 field2 yy field3 bb field4 300
HMSET 102 field1 102 field2 xx field3 bb field4 300
HMSET 103 field1 103 field2 yy field3 bb field4 300
HMSET 104 field1 104 field2 xx field3 bb field4 300

I want to retrieve all the records having field2 = xx (this is like where clause from SQL)

I think it should be done my creating secondary index on field2 but not sure how to write it.

Mark Setchell
210k32 gold badges308 silver badges502 bronze badges
asked Feb 6, 2019 at 16:00

2 Answers 2

1

Redis doesn't provide such functionality.

Also, Redis doesn't allow any indexes to be created.

Alternatively, it provides various data structures for you to save data according to your access needs eg: list, hashmap, set, sorted sets, etc

For your case, you'll have to manually iterate through all the records to get the desired results.

answered Feb 6, 2019 at 17:19
Sign up to request clarification or add additional context in comments.

Comments

0

I think you should create a reverse index for your keys and value. i.e.

 "value" ---> {{fieldName, HSETNAME}}
 Ex : xx --> {{field2,101},{field3,104}}

Iterating over proper key,value you can get the HMSET name and then you can retrieve all the records from it.

It is just that you have to manipulate your keys and values according to your usecase. You can find more info here: How do you search for keys with a value? For example get all KEYS where the value is "somevalue"

answered Feb 6, 2019 at 17:34

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.