Unable to create object of JedisCluster using Set<HostAndPort>, GenericObjectPoolConfig

59 views
Skip to first unread message

Akash

unread,
Feb 13, 2023, 8:04:11 AM2/13/23
to Jedis
Hello All,

I'm upgrading my current jedis library from 2.9.0 to 4.3.1 and I'm facing an issue which is preventing me from creating jar using gradle command.

Description - 
Earlier with Jedis 2.9.0, we were using following configuration while creating the connection: 
Set<HostAndPort> connectionPoints = new HashSet<HostAndPort>();
<Setting hosts and ports>

final JedisPoolConfig poolConfig = new JedisPoolConfig();
<setting some configs for poolConfig>

JedisCluster cluster= new JedisCluster(connectionPoints, poolConfig);




But in Jedis 4.3.1, since there is no constructor for  JedisPoolConfig, I had to create the object for GenericObjectPoolConfig as below:

final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
<setting some configs for poolConfig>

JedisCluster cluster= new JedisCluster(connectionPoints, poolConfig);


And everything was working as expected on local, it was fetching the result from staging server correctly and even handling load as well

But when I tried building the project using gradle command (gradlew clean build) it gave me below error - 
error: no suitable constructor found for JedisCluster(Set<HostAndPort>,GenericObjectPoolConfig)
                        JedisCluster cluster= new JedisCluster(connectionPoints, poolConfig);

 constructor JedisCluster.JedisCluster(HostAndPort,int) is not applicable
      (argument mismatch; Set<HostAndPort> cannot be converted to HostAndPort)
    constructor JedisCluster.JedisCluster(HostAndPort,GenericObjectPoolConfig<Connection>) is not applicable
      (argument mismatch; Set<HostAndPort> cannot be converted to HostAndPort)
    constructor JedisCluster.JedisCluster(Set<HostAndPort>,int) is not applicable
      (argument mismatch; GenericObjectPoolConfig cannot be converted to int)
    constructor JedisCluster.JedisCluster(Set<HostAndPort>,GenericObjectPoolConfig<Connection>) is not applicable
      (argument mismatch; GenericObjectPoolConfig cannot be converted to GenericObjectPoolConfig<Connection>)
    constructor JedisCluster.JedisCluster(Set<HostAndPort>,JedisClientConfig) is not applicable
      (argument mismatch; GenericObjectPoolConfig cannot be converted to JedisClientConfig)


I know the constructor is not available of same type but somehow it was working fine on local then why it is giving issue while creating the build. Please correct me if I'm making any mistake.

Thanks

Sazzadul

unread,
Sep 12, 2023, 6:17:19 AM9/12/23
to Jedis
Ahh, generics.

Instead of 
final GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
you have to
final GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();

You can also simply do
final ConnectionPoolConfig poolConfig = new ConnectionPoolConfig();
Reply all
Reply to author
Forward
0 new messages