Redis: using ZRANGE to search for a single value?

76 views Asked by At

If in a Redis database a sorted set is filled with decimal values, how can I search in it for an exact value given as a decimal value, under the condition that exactly this decimal value was also used when filling the sorted set?

Since Redis does the conversion to binary for us, wouldn't the rounding error when using ZADD be just exactly the same as when using ZSCORE? So if e.g. a key was added with score 0.1, can I retrieve it by using ZRANGE <sortedset> 0.1 0.1?

In other words, I'm looking for the minimal Δ that I should use for this special case of float comparison in ZRANGE <sortedset> <value>-Δ <value>+Δ. In my opinion, Δ = 0 should work.

Of course, I might get other keys with associated decimal values that weren't originally used when filling but that is unavoidable. Their number should be just as low as possible.

0

There are 0 answers