为双堆栈集群配置首选协议(Memcached) - Amazon ElastiCache
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

为双堆栈集群配置首选协议(Memcached)

对于 Memcached 集群,您可以使用 IP 发现参数控制客户端将用于连接到集群中的节点的协议。IP 发现参数可以设置为IPv4或IPv6。

IP 发现参数控制 config get 集群输出中使用的 IP 协议。这反过来又将决定支持自动发现 Memcached 集群的客户端使用 ElastiCache 的 IP 协议。

更改 IP 发现不会导致连接的客户端出现任何停机。但是,更改需要一些时间才能传播。

监视适用于 Java 和 Php 的 getAvailableNodeEndPoints 的输出,并监视 getServerList 的输出。一旦这些函数的输出报告IPs了集群中所有使用更新协议的节点,则更改已完成传播。

Java 示例:

MemcachedClient client = new MemcachedClient(new InetSocketAddress("xxxx", 11211)); Class targetProtocolType = Inet6Address.class; // Or Inet4Address.class if you're switching to IPv4 Set<String> nodes; do { nodes = client.getAvailableNodeEndPoints().stream().map(NodeEndPoint::getIpAddress).collect(Collectors.toSet()); Thread.sleep(1000); } while (!nodes.stream().allMatch(node -> { try { return finalTargetProtocolType.isInstance(InetAddress.getByName(node)); } catch (UnknownHostException ignored) {} return false; }));

Php 示例:

$client = new Memcached; $client->setOption(Memcached::OPT_CLIENT_MODE, Memcached::DYNAMIC_CLIENT_MODE); $client->addServer("xxxx", 11211); $nodes = []; $target_ips_count = 0; do { # The PHP memcached client only updates the server list if the polling interval has expired and a # command is sent $client->get('test'); $nodes = $client->getServerList(); sleep(1); $target_ips_count = 0; // For IPv4 use FILTER_FLAG_IPV4 $target_ips_count = count(array_filter($nodes, function($node) { return filter_var($node["ipaddress"], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); })); } while (count($nodes) !== $target_ips_count);

在 IP 发现更新之前创建的任何现有客户端连接仍将使用旧协议进行连接。一旦在集群发现命令的输出中检测到更改,所有经过验证的客户端都将使用新的 IP 协议自动重新连接到集群。但是,这取决于客户端的实现。