Assuming I have a structure such as:
house{rooms: 2, bathrooms: 1, square-feet: 1000},
house{rooms: 3, bathrooms: 1.5, square-feet: 1200},
house{rooms: 5, bathrooms: 3, square-feet: 1400},
Assuming I want to retrieve all houses where rooms = 3, how would I do that? Currently the key for each object is the zipcode which I need to use to look up and sort. I know in mongoose you can do something like:
var house = House.find({rooms: '3'}); 
but I can't find the equivalent command using redis.
- 
 You don't, unless you create another structure in redis keyed on # of rooms. There isn't any indexing in redis except what you build.hobbs– hobbs2015年03月08日 08:15:24 +00:00Commented Mar 8, 2015 at 8:15
- 
 Thanks @hobbs. Is there any inmemory cache object that would let me do the above? I guess if I want to do search by # of rooms, then I'd have to create a separate object that is basically a clone of the data of the current collection?StackOverflowed– StackOverflowed2015年03月08日 08:17:18 +00:00Commented Mar 8, 2015 at 8:17
1 Answer 1
Try the ZADD Command to sort the houses by #rooms ZADD is a ordered set that allows indexing by numbers.
ZADD "sorted set name" "sorting value" "value" "key"
so in your example :
ZADD housesByRooms 2 house1 
ZADD housesByRooms 3 house2 
(and so on you can also add multiple values at once)
later you can get them by ZRANGE
ZRANGE "sorted set name" "from" "to"
for example 
ZRANGE housesByRooms 2 5 
to get houses from 2 to 5 rooms 
http://redis.io/commands/zrange
key to redis is to check the commands and test them :)