本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
使用适用于 .NET 的 ElastiCache Cluster Client
注意
截至 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 Cluster Client 以连接到集群配置端点,并将数据项目添加至缓存中。借助 Auto Discovery,程序将在没有任何进一步干预的情况下连接至集群中的所有节点。
// ***************** // 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