Redis - Search for data modeling offers

I use Redis to store data logs from many analog sensors. My goal is to sort the data according to the timestamp of the log and retrieve data from a specific date-time range. My original data model was to use the name of the sensor as a key and have a hash for each timestamp and a value attached to the hash button.

So. if I have SensorA, SensorB and SensorC, executing the keys * will return 1. SensorA, 2. SensorB and 3. SensorC. Running hget SensorB 20110111172900 will return, say 25.

The problem with the current simulation is that it does not allow sorting by timestamp, or so I think, since everything I tried failed.

Someone will be able to propose a data model that would allow you to sort and retrieve ranges of data, or suggest the right sorting arguments that would allow this in the above data model.

+3
source share
1 answer

A sorted collection is probably better than a hash in this case.

The value will be a combination of the time stamp and the sensor value. The account will be a timestamp. Use ZRANGEBYSCORE to get the values. Both reads and writes go from O (1) to O (Log (N)), but you get the ability to return a range of values.

You can also use the list to enter O (1). Reading will be O (N) to get a specific record, but getting the latest records will be O (1).

+6
source

Source: https://habr.com/ru/post/1784845/


All Articles