I am using Amazon ElastiCach for Redis to store some items. In one method I am calling redis 3 or 4 times with one jedis client getted from JedisPool. After last call to redis both JedisPool and Jedis are closed. I call this method a 50 time in a minute. It just stops working in some point with messages: java.lang.Long cannot be cast to java.util.List java.util.ArrayList cannot be cast to java.lang.Long
Shoud I make it work one call to redis - one Jedis from JedisPool?
Here is my code:
AmazonElastiCacheClient client = new AmazonElastiCacheClient(awsElastiCashCredentials);
Region elastiCachRegion = Region.getRegion(Regions.fromName(amazonProps.getElastiCachRegion()));
client.setRegion(elastiCachRegion);
DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();
dccRequest.setShowCacheNodeInfo(true);
DescribeCacheClustersResult clusterResult = client.describeCacheClusters(dccRequest);
JedisPool pool = null;
List<CacheCluster> cacheClusters = clusterResult.getCacheClusters();
for (CacheCluster cacheCluster : cacheClusters) {
if (cacheCluster.getCacheClusterId().equals("001")) {
for (CacheNode cacheNode : cacheCluster.getCacheNodes()) {
String addr = cacheNode.getEndpoint().getAddress();
int port = cacheNode.getEndpoint().getPort();
try {
pool = new JedisPool(addr, port);
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
}
}
}
and method:
try (JedisPool pool = amazonElastiCacheService.connectToCachCluster()) {
try (Jedis jedis = pool.getResource()) {
fileEmail(jedis);
}
}
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
}