使用.net memcached客户端连接到amazon弹性缓存



我试图连接到亚马逊的弹性缓存使用.NET与以下代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Amazon.ElastiCacheCluster;
using Enyim.Caching;
using Enyim.Caching.Configuration;
using Enyim.Caching.Memcached;
namespace AmazonElasticCache
{
    class Program
    {
        static void Main(string[] args)
        {
            ElastiCacheClusterConfig config = new ElastiCacheClusterConfig();
            MemcachedClient memClient = new MemcachedClient(config);

            // add data to the cluster
            if (memClient.Store(StoreMode.Set, "key", "some data"))
            {
                Console.WriteLine("Successfully added data to cache.");
            }
            else
            {
                Console.WriteLine("Failed adding data to cache.");
            }

            var dataInStore = memClient.Get<string>("key");
            if (dataInStore == "some data")
            {
                Console.WriteLine("Successfully read data from store.");
            }
            else
            {
                Console.WriteLine("Failed reading data from cache.");
            }

            if (memClient.Remove("key"))
            {
                Console.WriteLine("Successfully removed data from store.");
            }
            else
            {
                Console.WriteLine("Failed removing data from cache. ");
            }
            Console.WriteLine("Now adding a complex object");
            // add data to the cluster
            if (memClient.Store(StoreMode.Set, "key", new Itinerary()))
            {
                Console.WriteLine("Successfully added data to cache.");
            }
            else
            {
                Console.WriteLine("Failed adding data to cache.");
            }
            var itinerary = memClient.Get<Itinerary>("key");
            if (itinerary != null)
            {
                Console.WriteLine("Successfully read data from store.");
            }
            else
            {
                Console.WriteLine("Failed reading data from cachee.");
            }

            if (memClient.Remove("key"))
            {
                Console.WriteLine("Successfully removed data from store.");
            }
            else
            {
                Console.WriteLine("Failed removing data from cache. ");
            }
        }
    }
    [Serializable]
    public class Itinerary
    {
        public string Name { get; set; }
        public string Id { get; set; }
        public string[] SomeOtherStuff { get; set; }
    }
}

在app.config.

 <configSections>
        <section name="clusterclient" type="Amazon.ElastiCacheCluster.ClusterConfigSettings, Amazon.ElastiCacheCluster" />
    </configSections>
    <clusterclient>
        <!-- the hostname and port values are from step 1 above -->
        <endpoint hostname="my-cache-name.cfg.usw2.cache.amazonaws.com" port="11211" />
    </clusterclient>

控制台应用程序没有崩溃,所有操作都不起作用。我正在浏览所有的失败路径。我错过了什么?

从上面的代码,我认为你是试图从本地主机连接到AWS弹性服务。要做到这一点,您需要遵循一些步骤。更多信息请参考这个答案。链接

最新更新