I suspect the problem has a couple of dimensions.
ZREMRANGEBYSCORE has a complexity of
O(log(N)+M) which is not great, especially the
M bit - so if you’re removing 10k samples, it will be slow.
- This key is being hit by both a frequent but light
ZADD and then is compounded by infrequent but heavy
First, consider splitting it along key lines - each hour gets it’s it own ZSET. That way you can just expire the key instead of deleting it, if possible. Your ZRANGEBYSCORE may become more complicated as you’re checking multiple keys, but it can be done in a deterministic way.
I will also say this is a perfect use for RedisTimeSeries, as mentioned above. It will likely be faster / smaller out-of-the-box, especially given the way you’re using zsets currently.