Nespl NS3
Nespl NS3

Reputation: 52

Redis storing historical data

I have data generated on daily basis. let me explain through a example: On World Market, the price of Gold change on seconds interval basis. and i want to store that price in Redis DBMS.

 Gold 22 JAN  11.02PM X-price
      22 JAN  11.03PM Y-Price
      ...
      24 DEC  11.04PM X1-Price

Silver 22 JAN 11.02PM M-Price
       22 JAN 11.03PM N-Price

I want to store this data on daily basis. want to apply ML (Machine Leaning) on last 52 Week data. Is this possible? Because As my knowledge goes. redis work on Key Value. if this is possible. Can i get data from a specific date(04 July) and DateRange(01 Feb to 31 Mar)

Upvotes: 1

Views: 3673

Answers (1)

Carl Zulauf
Carl Zulauf

Reputation: 39558

In redis, a Sorted Set is appropriate for time series data. If you score each entry with the timestamp of the price quote you can quickly access a whole day or group of days using the ZRANGEBYSCORE command (or ZSCAN if you need paging).

The quote data can be stored right in the sorted set. If you do this make sure each entry is unique. Adding a record to a sorted set that is identical to an existing one just updates the existing record's score (timestamp). This moves the old record to the present and erases it from the past, which is not what you want.

I would recommend only storing a unique key/ID for each quote in the sorted set, and store the data in it's own key or hash field. This will allow you to create additional indexes for the data as needed and access specific records more easily if necessary.

Upvotes: 2

Related Questions