0

i'm looking for a faster way to lookup a collection of keys in redis.

that's what i need to do:

HGET "user:001:coins" "2013-05-01"

it looks up stored coins for a user on a specific day.

Now i want to lookup all stored coins for a date range of a month:

HGET "user:001:coins" "2013-05-01"
HGET "user:001:coins" "2013-05-02"
....

Thats getting slow becasue i have to do that for 120 different users over 2 months. Is there a faster/better way to do this ?

one idea i had would be to add another key which holds the calculated coins amount for a month, and always recalculate the key if there is a change.

HGET "user:001:coins" "2013-05"

but that would mean additional programming logic, which i would like to avoid.

4

1 回答 1

0

Restructuring your data is not a bad idea even if it does require additional work. Fetching once is always faster than fetching N times.

If you can group your operations together, why not use HMGET?

HMGET "user:001:coins" "2013-05-01" "2013-05-02" ...
于 2013-05-09T15:13:07.217 回答