使用適用於 Java 的 ElastiCache 叢集用戶端 - Amazon ElastiCache

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用適用於 Java 的 ElastiCache 叢集用戶端

以下程式會示範如何使用 ElastiCache 叢集用戶端連線到叢集組態端點,然後將資料項目新增到快取。使用自動探索,程式便會連線到叢集內的所有節點,而不會進行其他介入。

package com.amazon.elasticache; import java.io.IOException; import java.net.InetSocketAddress; // Import the &AWS;-provided library with Auto Discovery support import net.spy.memcached.MemcachedClient; public class AutoDiscoveryDemo { public static void main(String[] args) throws IOException { String configEndpoint = "mycluster.fnjyzo.cfg.use1.cache.amazonaws.com"; Integer clusterPort = 11211; MemcachedClient client = new MemcachedClient( new InetSocketAddress(configEndpoint, clusterPort)); // The client will connect to the other cache nodes automatically. // Store a data item for an hour. // The client will decide which cache host will store this item. client.set("theKey", 3600, "This is the data value"); } }