class TestTimeSeries(object): def setup_method(self): self.client = MockRedisClient() self.timeseries = TimeSeries(self.client, 'test') timestamps = [0, 0, 1, 1, 1, 60] for timestamp in timestamps: self.timeseries.insert(timestamp) def teardown_method(self): pass def test_insert(self): assert int(float(self.client._data['test:1sec:0'])) == 2 assert int(float(self.client._data['test:1sec:1'])) == 3 assert int(float(self.client._data['test:1sec:60'])) == 1 assert int(float(self.client._data['test:1min:0'])) == 5 assert int(float(self.client._data['test:1min:60'])) == 1 assert int(float(self.client._data['test:1hour:0'])) == 6 assert int(float(self.client._data['test:1day:0'])) == 6 def test_fetch(self): begin_timestamp = 0 end_timestamp = 60 results = self.timeseries.fetch('1min', begin_timestamp, end_timestamp) assert results[0]['timestamp'] == 0 assert int(float(results[0]['value'])) == 5 assert int(float(results[1]['timestamp'])) == 60 assert int(float(results[1]['value'])) == 1
from redis import Redis from timeseries import TimeSeries client = Redis(port=9005, db=0) client.flushdb() ts = TimeSeries(client, 'test') before = client.info(section='memory') for timestamp in range(60 * 60): ts.insert(timestamp) after = client.info(section='memory') print(after['used_memory'] - before['used_memory'])