ElastiCache Endpoint Types

ElastiCache Endpoint 是提供給客戶去連接使用的,除每一個節點的 Node endpoint,還有 Redis 在非集群模式下的 Primary endpoint 及 Reader endpoint,這幾種 Endpoint 是常被誤用的。另外在 Redis 集群模式下及 Memcached 只有 Configuration endpoint 及每一個節點的 Node endpoint,並沒有Primary/Reader endpoint。

Jerry’s Notes
What’s next?
3 min readMar 20, 2022

--

Q: Types of connection Endpoint?

Node endpoint: Redis standalone node, use the node’s endpoint for both read and write operations. 記錄該節點的IP位置。

Primary endpoint: Redis (cluster mode disabled) clusters, use the Primary Endpoint for all write operations. 在非集群模式下,只會回傳該 Redis Cluster的”主”節點IP位置。

Reader endpoint: Use the Reader Endpoint to evenly split incoming connections to the endpoint between all read replicas. 在非集群模式下,只會回傳該 Redis Cluster下,”所有從節點(只讀副本)”節點IP位置。

Reader endpoint only splits incoming connections in round robin fashion with TTL of 5 seconds. The distribution of actual requests depends things like pattern of your connections, DNS caching etc. For example, DNS caching for longer duration in application or by client making use of reader endpoint can lead to calls to single replica. If socket connections are kept open for long period of time, requests with those connections would go to the same replica.

Use the individual Node Endpoints for read operations (In the API/CLI these are referred to as Read Endpoints).

Configuration endpoint: 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). On the other head, memcahed can using Auto Discover to access Configuration endpoint.

Redis 在集群模式下: 會回傳該 Redis Cluster下,”所有節點”的IP位置,前端應用程序,必需連接其中一個節點,然後使用 cluster nodes 去取得該 Redis Cluster 節點角色的拓墣資訊,進而對每一個節點進行命令操作。

Memcahed: 會回傳該 memcached cluster 下,”所有節點的其中一台節點的IP位置,而該筆 DNS record TTL 是15秒,前端應用程序,必需連接其中一個節點,然後透過 Memcache client SDK(Auto Discover),使用命令去取得該 memcache Cluster 節點角色的拓墣資訊,進而對每一個節點進行命令操作。

常用問題

Q: 為什麼我的 Redis 應用在寫入時,出現 ReadyOnly 的錯誤。

!!! 常見的問題,是您寫入數據到 Reader endpoint — 只讀副本(Replica nodes)的節點,所以無法寫入。

Q: 我的 ElastiCache Redis 集群有3個從節點,當我存取 Reader endpoint,是否會幫我平均到後端3個從節點嗎?

A: 不會,Reader endpoint 會回覆所有只讀副本(Replica nodes)的節點的IP位置,他只是一個 DNS record 記錄。

Q: 我的集群有開啟 Cluster-mode Enabled,當我連接 Configuration Endpoint 時,怎麼知道那個節點是從節點(只讀節點)

A: 您的前端應用程序(Redis Client),必需支援 Cluster-mode,並且必需更新集群拓墣資訊(命令: cluster-nodes),該資訊包含節點角色、節點IP位置、節點管理 Slots 的數量等等,然後您的前端應用去對操作節點,來建立連線。

[+] CLUSTER NODES:
https://redis.io/commands/cluster-nodes

Each node in a Redis Cluster has its view of the current cluster configuration, given by the set of known nodes, the state of the connection we have with such nodes, their flags, properties and assigned slots, and so forth.

ElastiCache Memcached Auto Discover
Auto Discovery 是 ElastiCache for Memcached 提供的 Client Library,讓使用者可以容易地去管理 Memcached Cluster 節點清單資料(節點拓墣-Node Topology),當節點數量及IP位置變化時,Memcached Client 可以透過 Auto Discovery 的功能,自動地去更新節點清單的資訊。

!!! 此外,ElastiCache Memcached Configuration endpoint 每次只會回覆”其中”一個節點的IP位置,而不像 ElastiCache Redis Configuration endpoint 會回覆所有節點的IP位置。

--

--

Jerry’s Notes
What’s next?

An cloud support engineer focus on troubleshooting with customer reported issue ,and cloud solution architecture.