Want to use Redis as an events statistics store

后端 未结 1 1492
猫巷女王i
猫巷女王i 2021-01-28 05:54

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

相关标签:
1条回答
  • 2021-01-28 06:37

    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.

    0 讨论(0)
提交回复
热议问题