Reputation: 1025
I am really interested in Redis, I have an idea and wanted to know if it is a suitable use case, or if it is not any other suggestions on a data store. Also any tips on storing the data would be appreciated.
My idea is just a simple event system so an event happens and it is stored in redis as follows
Key | Value [unixtimestamp]:[system]:[event] | [result]
The data could be anything sales, impressions, errors, api response times, page load times any real time analytics. I then want to be able to make graphs based on that data.
Upvotes: 0
Views: 2740
Reputation: 50052
This isn't an ideal design because it won't support your read pattern effectively and it will probably wasteful in terms of RAM if your [result] is short/small. Instead, look into using Redis' sorted sets with the timestamp as score, in the following fashion:
ZADD [system]:[event] [timestamp] [result]
Note that set members have to be unique so if [result]'s cardinality is low, make it unique by concatenating the timestamp to it (and filtering it out when you graph), i.e.:
ZADD [system]:[event] [timestamp] [result]:[timestamp]
This way you'll be able to fetch ranges of measurements by calling ZRANGEBYSCORE and graphing the results.
Upvotes: 2