jedis: ClassCastException - [B cannot be cast to java.lang.Long
I am using Jesque which uses Jedis as its Redis client, so I am not entirely sure if this is an issue in Jedis or Jesque.
I am receiving this error:
java.lang.ClassCastException
[B cannot be cast to java.lang.Long
at redis.clients.jedis.Connection.getIntegerReply(Connection.java:178)
at redis.clients.jedis.Jedis.incr(Jedis.java:605)
at net.greghaines.jesque.worker.WorkerImpl.success(WorkerImpl.java:520)
at net.greghaines.jesque.worker.WorkerImpl.execute(WorkerImpl.java:503)
at net.greghaines.jesque.worker.WorkerImpl.process(WorkerImpl.java:465)
at net.greghaines.jesque.worker.WorkerImpl.poll(WorkerImpl.java:405)
at net.greghaines.jesque.worker.WorkerImpl.run(WorkerImpl.java:216)
at java.lang.Thread.run(Thread.java:679)
I read that Jedis isnt thread-safe and in fact I dont try to re-use any Jedis clients in my Threads, I create new instances (I am refactoring this to use JedisPool).
The exception is not consistently reproducible.
About this issue
- Original URL
- State: closed
- Created 13 years ago
- Comments: 41
Commits related to this issue
- possible bug fix : avoid returning to pool if broken. https://github.com/xetorthio/jedis/issues/186 — committed to flipkart-incubator/chronosq by rajatflipkart 8 years ago
I really don’t know nothing about Gresque and how it uses Jedis underneath. But I am almost 100% sure that this error is because of reusing jedis instance from different threads. If you are using JedisPool, make sure to return Jedis either using returnResource or returnBrokenResource. Also if you are opening a pipeline, remember to close it before returning the resource to the pool. Try to find a script that reproduce this error and send it to me!
On Tue, Jul 26, 2011 at 2:43 PM, ruckus < reply@reply.github.com>wrote:
I got the exact same error a couple times an hour when I used the same connection in a runnable called 20ms later. This is what I originally had.
I changed it to this and it’s been working flawlessly for a few days now.
@hozouhing @AmaranthLIS I’m not sure what your situation is, but if you’re using the same connection more than once then I would try getting a new one. It seems like (at least in my case), it’s a usage error rather than a bug in Jedis.
I wasn’t able to reproduce it easily. It happens on my server after a few hours of continuous running. I guess it occurs because I’m not closing disconnected clients but try to reconnect them:
if (connection == null) { connection = jedisPool.getResource(); }if (!connection.isConnected()) { connection.connect(); }@SKras @guperrot
returnXXXResourcehas been deprecated since Jedis 2.5 onwards. Please usejedis.close()in yourfinallyblock instead.@SKras @guperrot is correct in his comment. Seems like you’re returning broken jedis instances to the pool. Again, use
jedis.close()to return instances propertly.+1 changing the pool.returnResource(jedis) to jedis.close() fixed my issue as well
Yes, change the pool.returnResource(jedis) to jedis.close() fixed the problem for me.