Reputation: 1783
I am playing around with storing simple Analytics data in Reds.
I'm starting out by storing simple pageview data for a blog post. I'm using the following model:
$redis.incr '2014:7:29:post:123:views'
So i'm storing 'YEAR:MONTH:DAY:ENTITY:ID:ACTION' as the key.
What is the best way to get back the value (sum?) of the keys for all Posts with ID 123?
Ultimately I'd like to be able to create a spark line for the # of views by Day for this Post.
I'm getting the feeling I am approaching this the wrong way.....
Upvotes: 0
Views: 2449
Reputation: 1211
You can increase the count value by HINCRBY
command rather than INCR
,
so that you can get all count values of the key by HGETALL
command.
To increase the count value:
$redis.hincrby 'post:123:views' '2014:7:29' 1
To get all count values for the key:
$redis.hgetall 'post:123:views'
Upvotes: 1