Fast comes at a price. redis is a non-relational database. To query based on conditions, you must manually create indexes for the data.
Hashset can be used to save objects. Assume that the hashset key is in the form 'user:name'.
Conditional queries can use sorted set. key is a field of the object. When searching for a name, you can use the zRangeByLex command:
After that, you can use user:lijiang and user:likui to get relevant information.
To find people whose names start with li, you can use '[li (lj') to find strings in the semi-open range [li..., lj). When redis compares a string and its prefix, the longer one is larger (for example: liA > li, liABCDEF... < lj).
(Note: zRangeByLex requires redis version >2.8.9)
To search for age conditionally, you can use the zRangeByScore command of sorted set:
Fast comes at a price. redis is a non-relational database. To query based on conditions, you must manually create indexes for the data.
Hashset can be used to save objects. Assume that the hashset key is in the form 'user:name'.
Conditional queries can use sorted set. key is a field of the object. When searching for a name, you can use the zRangeByLex command:
After that, you can use user:lijiang and user:likui to get relevant information.
To find people whose names start with li, you can use '[li (lj') to find strings in the semi-open range [li..., lj). When redis compares a string and its prefix, the longer one is larger (for example: liA > li, liABCDEF... < lj).
(Note: zRangeByLex requires redis version >2.8.9)
To search for age conditionally, you can use the zRangeByScore command of sorted set:
The three parameters of zRangeByScore are: key, min, max (closed interval)
Reference: http://redis.io/commands/