etaty / rediscala

Non-blocking, Reactive Redis driver for Scala (with Sentinel support)
Apache License 2.0
790 stars 142 forks source link

Decoding a zscore result of `inf` or `-inf` fails #83

Closed ethul closed 9 years ago

ethul commented 9 years ago

I am using rediscala @ 1.4.2. If I add a member to a sorted set with positive or negative infinity as the score, running the zscore command for that member of the sorted set results in an exception due to parseDouble.

In the example below, we get inf and -inf as the resulting scores from redis.

$ redis-cli
127.0.0.1:6379> zadd test:zset Inf "test"
(integer) 1
127.0.0.1:6379> zscore test:zset "test"
"inf"
127.0.0.1:6379> zadd test:zset -Inf "test1"
(integer) 1
127.0.0.1:6379> zscore test:zset "test1"
"-inf"
127.0.0.1:6379> exit

However, java.lang.Double.parseDouble expects Infinity or -Infinity. Also below is an example trying to parse inf.

$ scala
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_31).
Type in expressions to have them evaluated.
Type :help for more information.

scala> Double.PositiveInfinity
res0: Double = Infinity

scala> Double.PositiveInfinity.toString
res1: String = Infinity

scala> java.lang.Double.parseDouble(res1)
res3: Double = Infinity

scala> Double.NegativeInfinity.toString
res4: String = -Infinity

scala> java.lang.Double.parseDouble(res4)
res5: Double = -Infinity

scala> java.lang.Double.parseDouble("inf")
java.lang.NumberFormatException: For input string: "inf"
  at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
  at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
  at java.lang.Double.parseDouble(Double.java:538)
  ... 33 elided

scala> :q
etaty commented 9 years ago

thanks