Query on non primary key

20 views
Skip to first unread message

darshan kamat

unread,
Nov 22, 2017, 6:22:47 AM11/22/17
to Redis DB
Hi ,

I am storing my object as hash:

key - customer:123

name:darshan
age:25

Now i need to query based on age, and get the list of customerids. 


(I know the workaround of storing the reverse as a Set.But i dnt want to explicitly create individual sets for the same)

Is there any other alternative.Redis website talks about secondary index bt only for data structure - List,Set and sorted set 
Pls help on the same

Itamar Haber

unread,
Nov 22, 2017, 8:00:37 AM11/22/17
to Redis DB
Hello Darshan,

Since age is a numeric attribute, you can use a Sorted Set to index your customers' ids (elements in the Sorted Set) and their ages (scores in the Sorted Set). You can query that index with the ZRANGEBYSCORE command to retrieve id between any range of ages (scores).

I hope this answers your question, but feel free to clarify :)

Cheers,

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.



--

Itamar Haber | Chief OSS Education Officer
Redis Labs ~/redis

Mobile: +972 (54) 567 9692
Twitter: @itamarhaber
Skype: itamar.haber

darshan kamat

unread,
Nov 23, 2017, 12:28:31 AM11/23/17
to Redis DB
Hi,

Thanks for the reply,but that was just an example..My hash contains around 50-60 fields... and i need to query on the non primary key of around 5-10 fields in the hash ...and those fields are string.








On Wednesday, 22 November 2017 18:30:37 UTC+5:30, Itamar Haber wrote:
Hello Darshan,

Since age is a numeric attribute, you can use a Sorted Set to index your customers' ids (elements in the Sorted Set) and their ages (scores in the Sorted Set). You can query that index with the ZRANGEBYSCORE command to retrieve id between any range of ages (scores).

I hope this answers your question, but feel free to clarify :)

Cheers,
On Wed, Nov 22, 2017 at 1:22 PM, darshan kamat <dkdar...@gmail.com> wrote:
Hi ,

I am storing my object as hash:

key - customer:123

name:darshan
age:25

Now i need to query based on age, and get the list of customerids. 


(I know the workaround of storing the reverse as a Set.But i dnt want to explicitly create individual sets for the same)

Is there any other alternative.Redis website talks about secondary index bt only for data structure - List,Set and sorted set 
Pls help on the same

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Dvir Volk

unread,
Nov 23, 2017, 2:52:25 AM11/23/17
to redi...@googlegroups.com
Shameless plug alert, but this might actually be what you need - try indexing with the search module - http://redisearch.io
Reply all
Reply to author
Forward
0 new messages