user1978109
user1978109

Reputation: 737

Redis - Ranging with key

I have been trying to figure out how to an autocomplete type problem using the keys but I am not sure if this is possible. My datastruture would be as follows

 "Alice" -> "{person details}"
 "Bob" -> "{person details}"

I would like to do an autorange by selecting only keys in between a range but it appears this only works with the values. Any direction would be helpful.

Upvotes: 0

Views: 102

Answers (2)

zenbeni
zenbeni

Reputation: 7193

You can use sorted sets with redis "ZSET" which is the structure you are looking for.

You will have to define a "score" (double value) for each member of the ZSET then you can query a range of members by their scores of by their indexes (top 5 or from scores 10 to 50 for instance).

It is really performant as redis uses skip lists. Check ZSET in redis documentation: http://redis.io/topics/data-types

Upvotes: 1

Pixou
Pixou

Reputation: 1769

Redis is basically a big hashtable, which allows O(1) access to keys. It means that keys are hashed, and therefore it is impossible to search for keys within a range, without reading all the keys (obviously not an option).

My guess is that the best data structure for what you're looking for would be a tree, in particular a radix tree http://en.wikipedia.org/wiki/Radix_tree

I don't know if they are common and production-ready implementations as data store.

Upvotes: 1

Related Questions