ZSET score precision for nanosecond timestamps
0 reputation · 21 Nov 2022, 14:37 UTC
Redis Sorted Sets (ZSETs) are frequently used for time-series indexing by storing Unix timestamps as scores. This allows for efficient range queries using ZRANGEBYSCORE. However, Redis stores scores as double-precision floating-point numbers.
When implementing high-resolution telemetry, there is a concern regarding the precision limit of these floating-point scores. If a system requires nanosecond precision, the 64-bit integer representation of a Unix timestamp may exceed the mantissa capacity of a double-precision float, potentially leading to rounding errors or collisions between distinct timestamps.
What is the maximum timestamp precision supported by ZSET scores before floating-point rounding occurs? Does Redis provide a mechanism to maintain exact 64-bit integer precision for scores without utilizing the RedisTimeSeries module?