informatikr / hedis

A Redis client library for Haskell.
http://hackage.haskell.org/package/hedis
BSD 3-Clause "New" or "Revised" License
329 stars 127 forks source link

Bug report: Double type (zrangeWithscores) #74

Closed Thomas1995 closed 8 years ago

Thomas1995 commented 8 years ago

I found this bug while testing redis' sorted sets. The problem appeared when I wanted to add a value very close to 0. The following actions are done with redis-cli:

127.0.0.1:6379> ZADD test -0.000020221356243895889 PrPZck9bNdCcQ9qq3Ia
127.0.0.1:6379> ZRANGE test 0 -1 WITHSCORES
1) "PrPZck9bNdCcQ9qq3Ia"
2) "-2.0221356243895889e-05"

Now, if I want to use the "zrangeWithscores" function from "Database.Redis" on this sorted set, this happens:

runRedis conn $ zrangeWithscores "test" 0 (-1)
Right [("PrPZck9bNdCcQ9qq3Ia",-2.022135624389589)]

This is wrong, as it ignores the "e-05" part, which makes a big difference in this case.

I think the problem might be here: https://github.com/informatikr/hedis/blob/master/src/Database/Redis/Types.hs (lines 68-69).

instance RedisResult Double where
    decode r = maybe (Left r) (Right . fst) . F.readSigned F.readDecimal =<< decode r

as

$ ghci
λ> :set -XOverloadedStrings
λ> import qualified Data.ByteString.Lex.Fractional as F (readSigned, readDecimal)
λ> F.readSigned F.readDecimal $ "-2.0221356243895889e-05"
Just (-2.022135624389589,"e-05")
k-bx commented 8 years ago

Forgot to mention, fixed in 0.8.2.