클라이언트 모범 사례(Valkey 및 RedisOSS) - Amazon ElastiCache

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

클라이언트 모범 사례(Valkey 및 RedisOSS)

일반적인 시나리오의 모범 사례를 알아보고 가장 인기 있는 오픈 소스 Valkey 및 Redis OSS 클라이언트 라이브러리(redis-py, PHPRedis및 Lettuce)의 코드 예제와 함께 일반적으로 사용되는 오픈 소스 Memcached 클라이언트 라이브러리를 사용하여 ElastiCache 리소스와 상호 작용하기 위한 모범 사례를 따르세요.

듀얼 스택 클러스터(Valkey 및 RedisOSS)에 대한 기본 프로토콜 구성

클러스터 모드가 활성화된 Valkey 또는 Redis OSS 클러스터의 경우 IP Discovery 파라미터를 사용하여 클러스터의 노드에 연결하는 데 사용할 프로토콜 클라이언트를 제어할 수 있습니다. IP 검색 파라미터는 IPv4 또는 로 설정할 수 있습니다IPv6.

Valkey 또는 Redis OSS 클러스터의 경우 IP 검색 파라미터는 클러스터 슬롯(), 클러스터 샤드()클러스터 노드() 출력에 사용되는 IP 프로토콜을 설정합니다. 이러한 명령은 클라이언트가 클러스터 토폴로지를 검색하는 데 사용됩니다. 클라이언트는 이러한 명령IPs의 를 사용하여 클러스터의 다른 노드에 연결합니다.

IP Discovery를 변경해도 연결된 클라이언트는 가동 중지되지 않습니다. 하지만 변경 사항이 전파되려면 다소 시간이 소요됩니다. 변경 사항이 Valkey 또는 Redis OSS 클러스터에 대해 완전히 전파된 시기를 확인하려면 의 출력을 모니터링합니다cluster slots. 새 프로토콜과 IPs 함께 클러스터 슬롯 명령 보고서에서 반환된 모든 노드가 전송을 완료하면 변경 사항이 적용됩니다.

Redis-Py 사용 예제:

cluster = RedisCluster(host="xxxx", port=6379) target_type = IPv6Address # Or IPv4Address if changing to IPv4 nodes = set() while len(nodes) == 0 or not all((type(ip_address(host)) is target_type) for host in nodes): nodes = set() # This refreshes the cluster topology and will discovery any node updates. # Under the hood it calls cluster slots cluster.nodes_manager.initialize() for node in cluster.get_nodes(): nodes.add(node.host) self.logger.info(nodes) time.sleep(1)

Lettuce 사용 예제:

RedisClusterClient clusterClient = RedisClusterClient.create(RedisURI.create("xxxx", 6379)); Class targetProtocolType = Inet6Address.class; // Or Inet4Address.class if you're switching to IPv4 Set<String> nodes; do { // Check for any changes in the cluster topology. // Under the hood this calls cluster slots clusterClient.refreshPartitions(); Set<String> nodes = new HashSet<>(); for (RedisClusterNode node : clusterClient.getPartitions().getPartitions()) { nodes.add(node.getUri().getHost()); } Thread.sleep(1000); } while (!nodes.stream().allMatch(node -> { try { return finalTargetProtocolType.isInstance(InetAddress.getByName(node)); } catch (UnknownHostException ignored) {} return false; }));