简体   繁体   中英

What is a proper way to connect to AWS Elasticache (Redis cluster) from Java?

I'm new to AWS Elasticache redis , and I got below endpoint.

图片

I'm confused in either using Jedis and Redisson , because both provides single connection and cluster connection class.

Like in Jedis , for a single connection we can use:

Jedis conn = new Jedis("endpoint_address");

And for cluster connection we use:

Set<HostAndPort> jedisClusterNodes = new HashSet<HostAndPort>();
jedisClusterNodes.add(new HostAndPort("redis_cluster_ip", 7379));
JedisCluster jc = new JedisCluster(jedisClusterNodes);

These option also occur when I want to use Redisson . I'm not try to compare these two lib, my question is: WHICH ONE is the right method of connecting to AWS Redis Elasticache cluster, when you only have one end-point and still can utilize AWS auto scaling feature?

Expected answer is: use SINGLE or CLUSTER MODE.

Thanks :)

It depends on how you have the redis cluster configured. Whether or not cluster mode is enabled.

You can find it in the console

http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Endpoints.html

Redis (cluster mode disabled) clusters, use the Primary Endpoint for all write operations. Use the individual Node Endpoints for read operations (In the API/CLI these are referred to as Read Endpoints).

Redis (cluster mode enabled) clusters, use the cluster's Configuration Endpoint for all operations. You must use a client that supports Redis Cluster (Redis 3.2). You can still read from individual node endpoints (In the API/CLI these are referred to as Read Endpoints).

Or with the AWS CLI

aws elasticache describe-cache-clusters \
    --cache-cluster-id mycluster \
    --show-cache-node-info  

http://docs.aws.amazon.com/cli/latest/reference/elasticache/describe-cache-clusters.html

ConfigurationEndpoint -> (structure) Represents a Memcached cluster endpoint which, if Automatic Discovery is enabled on the cluster, can be used by an application to connect to any node in the cluster. The configuration endpoint will always have .cfg in it. Example: mem-3.9dvc4r.cfg.usw2.cache.amazonaws.com:11211

You should use Replicated configuration in Redisson for AWS Elasticache Redis or other similar hosted services. The usage is described in the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM