-2

ClassCastException occurs when I try to scan a large number of keys using opsForHash.scan() method. I am using Jedis 2.6.2 and I face this error only when the number of keys to be searched is large(~100,000). I have read solutions to this problem online and most of them are suggesting that the problem occurs due to connection pooling.

I am using Spring integration in my project and have set use-pool attribute as true(in JedisConnectionFactory) even though it is the default option. Since spring is supposed to manage the connections with redis, why am I still having this issue? Please suggest.

enter image description here

This is the Spring Configuration file I am using :

enter image description here

This is the java code where i am executing scan() : enter image description here

rvd
  • 2,214
  • 3
  • 13
  • 14

1 Answers1

1

I had this same problem. After searching a lot on the internet, I found that the problem occurs due to connection pooling problems. As you have mentioned, you have set use-pool to be true in the spring configuration. I by passed this problem by setting pooling as false. It turned out that I didn't need pooling and after that the problem didn't occur. You can try this solution if you don't explicitly need pooling. Here is the code snippet:

<bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
        p:hostName="" p:port="6379" p:usePool="false" /> 

Hope it helps!

chinmay
  • 21
  • 3