I'm using Redis to store data logs from many analog sensors. My goal is to sort the data according to a log time stamp and extract the data from a specific datetime range. My originial data model was to use the sensor name as the key and have a hash for each timestamp and the value attached to the hashkey.
So. if I have SensorA, SensorB and SensorC, doing a Keys * would return 1. SensorA, 2. SensorB and 3. SensorC. Doing hget SensorB 20110111172900 would return, let's say 25.开发者_JAVA技巧
The problem with the current modeling is that it doesn't allow sorting on the timestamp, or so I think since all I've tried has failed.
Would someone be able to suggest a data model that would allow sorting and extracting ranges of data, or suggest the proper sort arguments that would allow this in the data model above.
A sorted set is probably a better fit than a hash in this case.
The value would be a combination of timestamp and sensor value. The score would be the timestamp. Use ZRANGEBYSCORE to retrieve the values. Both read and write go from O(1) to O(Log(N)), but you gain the ability to return a range of values.
You could also use a list to get O(1) insertion. Reading would be O(N) for retrieving a specific entry, but getting the most recent entries would be O(1).
精彩评论