debasishg / scala-redis

A scala library for connecting to a redis server, or a cluster of redis nodes using consistent hashing on the client side.
1.02k stars 219 forks source link

Subscribe gives Protocol error: Got (3,[B@1acc768) as initial reply byte #231

Closed writeaditya closed 5 years ago

writeaditya commented 5 years ago

Hi,

I'am trying to create a pub sub using this project. Able to publish easily, but when trying to subscribe using below, it gives error as below.

val clients = new RedisClientPool("ip", port) clients.withClient { client => { client.subscribe("channelname") { f => println("message" + f) } } }

Error given is :-

Exception in thread "main" java.lang.Exception: Protocol error: Got (3,[B@1acc768) as initial reply byte at com.redis.Reply$$anonfun$8.applyOrElse(RedisProtocol.scala:120) at com.redis.Reply$$anonfun$8.applyOrElse(RedisProtocol.scala:118) at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36) at com.redis.Reply$$anonfun$queuedReplyLong$1.applyOrElse(RedisProtocol.scala:127) at com.redis.Reply$$anonfun$queuedReplyLong$1.applyOrElse(RedisProtocol.scala:127) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167) at com.redis.Reply$$anonfun$2.applyOrElse(RedisProtocol.scala:59) at com.redis.Reply$$anonfun$2.applyOrElse(RedisProtocol.scala:59) at scala.PartialFunction$OrElse.apply(PartialFunction.scala:167) at com.redis.Reply$class.receive(RedisProtocol.scala:139) at com.redis.RedisClient.receive(RedisClient.scala:103) at com.redis.R$class.asLong(RedisProtocol.scala:250) at com.redis.RedisClient.asLong(RedisClient.scala:103) at com.redis.SortedSetOperations$$anonfun$zcount$1.apply(SortedSetOperations.scala:147) at com.redis.SortedSetOperations$$anonfun$zcount$1.apply(SortedSetOperations.scala:147) at com.redis.Redis$class.send(RedisClient.scala:30) at com.redis.RedisClient.send(RedisClient.scala:103) at com.redis.SortedSetOperations$class.zcount(SortedSetOperations.scala:147) at com.redis.RedisClient.zcount(RedisClient.scala:103) at axestrack.liveData$$anonfun$main$3.apply(liveData.scala:169) at axestrack.liveData$$anonfun$main$3.apply(liveData.scala:167) at com.redis.RedisClientPool.withClient(Pool.scala:45) at axestrack.liveData$.main(liveData.scala:166) at axestrack.liveData.main(liveData.scala) messageE(java.lang.NumberFormatException: For input string: " subscribe")

Where is problem ?

debasishg commented 5 years ago

I will take a look soon .. meanwhile please take a look at https://github.com/debasishg/scala-redis/blob/master/src/test/scala/com/redis/PubSubSpec.scala#L35-L69 on the correct usage of pubsub in redis ..

Thanks.

debasishg commented 5 years ago

I just now tested with your code (modified the host and port) - Not sure what "ip" refers to in your host name ..

val clients = new RedisClientPool("localhost", 6379)
  clients.withClient { client =>
    client.subscribe("channelname") { f => println("message" + f) }
  }
}

I get the following output ..

messageS(channelname,1)

Looks ok to me ..

writeaditya commented 5 years ago

Thanks Debasish, It worked for me as well, not sure where it was giving error. Its working now , I just have to create a normal instance rather then pool. Much thanks for your time. Keep working on your project. Its wonderful and very helpful. Closing this ticket.