-1

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();
            }
Imaskar
  • 2,773
  • 24
  • 35
cojeca
  • 67
  • 1
  • 1
  • 7

1 Answers1

0

Looks like you are assigning List(ArrayList)of Object value to Long object. See line#/Class , method and modify.
Or check all the Long value assignments in your code, some where u r setting n ArrayList object to it.

e.g.

Long value;
List<?> myList = new ArrayList<?>();
value = myList ;

I dint find any problem from the code you shared.

TheSprinter
  • 1,523
  • 17
  • 30