Open afarber opened 1 year ago
I would like to share a workaround here for anyone with the TS.RANGE "wrong fromTimestamp" or "wrong toTimestamp" problem - you have to get rid of the fractional part by using math.floor:
EVAL "local time = redis.call('TIME'); local now = math.floor(time[1] * 1000 + time[2] / 1000); local start = now - tonumber(ARGV[1]); local tsrange = redis.call('TS.RANGE', KEYS[1], start, now); return tsrange" 1 12345678:5 1800000
(empty array)
It seems like a bug in TimeSeries module, fractional timestamps shouldn't break the TS:RANGE command.
As documented, timestamps are Unix time (integer, in milliseconds). The command parser expects a non-negative integer value and replies with an error if this is not the case.
Aren't all numbers in Lua floating point? Wouldn't it make sense to accept fractional timestamps too?
Since RedisTimeSeries stores timestamps as 64-bit unsigned integers (milliseconds since the Unix epoch), accepting floating-point values would be misleading. We would need to round or truncate the which may be unexpected and could be considered erroneous by some users due to an alleged loss of resolution.
Note also that starting with Redis Stack 7.2 Triggers and functions should be preferred over LUA scripts.
Good evening, I have the following question please:
With Azure Redis Cache (Enterprise E10 with TimeSeries module enabled) it is possible to retrieve all timestamps from a time series for the key "12345678:5" by calling:
But I am only interested in the timestamps/values of the recent 30 minutes (1800000 milliseconds).
So I calculate the timestamps "start" and "now" by the Lua script:
And then I try to call TS.RANGE using the Lua script:
Please advise me, what am I doing wrong?
My real background is that I try to call TS.ADD and TS.RANGE in my C# web app (the auto-expiration does not really seem to work, so I cannot use "TS.RANGE key - +", but have to specify the fromTimestamp, toTimestamp arguments to TS.RANGE explicitly):
I hope that I do not have to workaround my issue by modifying the for-loop above and comparing each timestamp one by one...
Thank you Alex