scala-redis
scala-redis copied to clipboard
evalBulk() return types and parsing fail
This is related to #128 and #129. Using "net.debasishg" %% "redisclient" % "3.4".
Case 1: trying explicitly to specify return type.
val result = redisPool.withClient(_.evalBulk[Int]("return 1", List.empty, List.empty))
Does not compile:
RedisTest.scala:48: could not find implicit value for parameter parse: com.redis.serialization.Parse[Int]
Case 2: Not specifying the return type:
val result = redisPool.withClient(_.evalBulk("return 1", List.empty, List.empty))
Compiles, but crashes at run time:
java.lang.Exception: Protocol error: Got (:,[B@7eab8553) as initial reply byte
at com.redis.Reply$$anonfun$8.applyOrElse(RedisProtocol.scala:121)
at com.redis.Reply$$anonfun$8.applyOrElse(RedisProtocol.scala:119)
at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
at com.redis.Reply$$anonfun$4.applyOrElse(RedisProtocol.scala:78)
at com.redis.Reply$$anonfun$4.applyOrElse(RedisProtocol.scala:78)
at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167)
at com.redis.Reply$class.receive(RedisProtocol.scala:140)
at com.redis.RedisClient.receive(RedisClient.scala:95)
at com.redis.R$class.asBulk(RedisProtocol.scala:243)
at com.redis.RedisClient.asBulk(RedisClient.scala:95)
at com.redis.EvalOperations$$anonfun$evalBulk$1.apply(EvalOperations.scala:13)
at com.redis.EvalOperations$$anonfun$evalBulk$1.apply(EvalOperations.scala:13)
at com.redis.Redis$class.send(RedisClient.scala:22)
at com.redis.RedisClient.send(RedisClient.scala:95)
at com.redis.EvalOperations$class.evalBulk(EvalOperations.scala:13)
at com.redis.RedisClient.evalBulk(RedisClient.scala:95)
at test.RedisTest$$anonfun$1.apply(RedisTest.scala:48)
IntelliJ indicates that the type of result in this case is Option[String]. That would be fine, I can convert it to an Int, but clearly Redis is not returning a String.
(Oh yes, I can use Lua tostring() on the return value, but that feels relatively stupid.)
@salokanto Did you ever find a fix to this?
@masonkirchner Nope. I'm using send("EVAL", ...) instead of evalBulk now, and parsing the results with asList, asInt, and others from the "aptly" named com.redis.R trait.
A bit hacky, but this will also solve the issue:
implicit val parse = Parse[Int](new String(_, "UTF-8").toInt)
redis.evalSHA[Int](params, ... )
or simply import the implicits if you don't want to copy/paste them
import Parse.Implicits._
redis.evalSHA[Int](params, ... )