gpt4 book ai didi

java - Amazon Elasticache Redis 集群 - 无法获取端点

转载 作者:IT王子 更新时间:2023-10-29 06:05:32 25 4
gpt4 key购买 nike

我需要在 Amazon Elasticache 中获取 Redis 集群的终端节点。以下代码适用于 Memcached 集群,但不适用于 Redis:

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;

import com.amazonaws.services.elasticache.AmazonElastiCacheClient;
import com.amazonaws.services.elasticache.model.DescribeCacheClustersRequest;
import com.amazonaws.services.elasticache.model.DescribeCacheClustersResult;
import com.amazonaws.services.elasticache.model.CacheNode;
import com.amazonaws.services.elasticache.model.CacheCluster;
import com.amazonaws.services.elasticache.model.Endpoint;

public class Redis {
public static void main(String[] args) {
AWSCredentials credentials =
new ProfileCredentialsProvider("default").getCredentials();
AmazonElastiCacheClient amazonClient = new AmazonElastiCacheClient(credentials);
amazonClient.setRegion(Regions.EU_WEST_1);
DescribeCacheClustersRequest dccRequest = new DescribeCacheClustersRequest();
dccRequest.setShowCacheNodeInfo(true);
dccRequest.withCacheClusterId("app-001");
DescribeCacheClustersResult clusterResult =
amazonClient.describeCacheClusters(dccRequest);

CacheCluster cacheCluster = clusterResult.getCacheClusters().get(0);
System.out.println("cluster: " + cacheCluster);
System.out.println("endpoint: " + cacheCluster.getConfigurationEndpoint());
}
}

输出是:

cluster: {CacheClusterId: app-001,ClientDownloadLandingPage: https://console.aws.amazon.com/elasticache/home#client-download:,CacheNodeType: cache.r3.large,Engine: redis,EngineVersion: 2.8.19,CacheClusterStatus: available,NumCacheNodes: 1,PreferredAvailabilityZone: eu-west-1a,CacheClusterCreateTime: Thu May 21 11:43:03 CEST 2015,PreferredMaintenanceWindow: mon:04:00-mon:05:00,PendingModifiedValues: {CacheNodeIdsToRemove: [],},CacheSecurityGroups: [],CacheParameterGroup: {CacheParameterGroupName: default.redis2.8,ParameterApplyStatus: in-sync,CacheNodeIdsToReboot: []},CacheSubnetGroupName: default,CacheNodes: [{CacheNodeId: 0001,CacheNodeStatus: available,CacheNodeCreateTime: Thu May 21 11:43:03 CEST 2015,Endpoint: {Address: app-001.3pusxn.0001.euw1.cache.amazonaws.com,Port: 6379},ParameterGroupStatus: in-sync,CustomerAvailabilityZone: eu-west-1a}],AutoMinorVersionUpgrade: true,SecurityGroups: [{SecurityGroupId: sg-3231f657,Status: active}],ReplicationGroupId: app,SnapshotRetentionLimit: 0,SnapshotWindow: 22:00-23:00}
endpoint: null

请注意集群对象如何包含端点信息(键:Endpoint),但是 getConfigurationEndpoint 返回 null

如何获取端点?

最佳答案

正如通常发生的那样,我在发布问题后立即找到了解决方案。在 Redis 中,您必须访问缓存节点:

Endpoint endpoint = cacheCluster.getCacheNodes().get(0).getEndpoint();

关于java - Amazon Elasticache Redis 集群 - 无法获取端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30371893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com