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

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

使用適用於 .NET 的 ElastiCache 叢集用戶端

注意

自 2022 年 5 月起,已淘汰 ElastiCache .NET 叢集用戶端。

適用於 ElastiCache 的 .NET 用戶端為開放原始碼資源,位於 https://github.com/awslabs/elasticache-cluster-config-net

.NET 應用程式通常會從其組態檔取得組態。以下是範例應用程式組態檔。

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="clusterclient" type="Amazon.ElastiCacheCluster.ClusterConfigSettings, Amazon.ElastiCacheCluster" /> </configSections> <clusterclient> <!-- the hostname and port values are from step 1 above --> <endpoint hostname="mycluster.fnjyzo.cfg.use1.cache.amazonaws.com" port="11211" /> </clusterclient> </configuration>

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

// ***************** // Sample C# code to show how to integrate with the Amazon ElastiCcache Auto Discovery feature. using System; using Amazon.ElastiCacheCluster; using Enyim.Caching; using Enyim.Caching.Memcached; public class DotNetAutoDiscoveryDemo { public static void Main(String[] args) { // instantiate a new client. ElastiCacheClusterConfig config = new ElastiCacheClusterConfig(); MemcachedClient memClient = new MemcachedClient(config); // Store the data for 3600 seconds (1hour) in the cluster. // The client will decide which cache host will store this item. memClient.Store(StoreMode.Set, 3600, "This is the data value."); } // end Main } // end class DotNetAutoDiscoverDemo