本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
注意
自 2022 年 5 月起, ElastiCache .NET 集群客户端已被弃用。
的.NET 客户端 ElastiCache 是开源的,网址为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 集群客户端连接到集群配置终端节点并将数据项添加到缓存中。借助 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