Redis Sets: store timestamps as keys

1,237 views
Skip to first unread message

Praveen Innamuri

unread,
Jun 14, 2016, 1:18:11 AM6/14/16
to Redis DB
We would like to store a series of time-series based data in Redis. So, one option would be store timestamp as keys, and then we would like to query for all the data between specific time slots. Here is the example:

key                             value
-----------------------------------
06-13-2016 6PM : [2, 3, 6, 4]
06-13-2016 7PM : [12, 23, 16, 4]
06-13-2016 8PM : [1, 2, 6, 4]

If we query for data between 06-13-2016 6PM and 7PM, I should get [2, 3, 6, 4]. Is there any way of achieving that in Redis?

AlexanderB

unread,
Jun 14, 2016, 1:35:49 PM6/14/16
to Redis DB

You should be able to achieve that using sorted sets. You would convert the timestamps to a format such as the unix epoc format. https://en.wikipedia.org/wiki/Unix_time

TL:DR, this sorts all timestamps as a universally incrementing counter, so it would work perfect as a sorted set score. 

Here's a great reference for this sort of use case I was able to find with a quick google search. http://first-time-ceo.tumblr.com/post/105297218212/redis-storing-time-series-data-in-a-sorted-set
Reply all
Reply to author
Forward
0 new messages