【问题标题】:connecting to amazon elastic cache using .net memcached client使用 .net memcached 客户端连接到亚马逊弹性缓存
【发布时间】:2017-09-25 13:22:12
【问题描述】:

我正在尝试使用 .NET 使用以下代码连接到 Amazon 的弹性缓存:

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>

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

【问题讨论】:

    标签: c#-4.0 amazon-web-services amazon-ec2 memcached


    【解决方案1】:

    从上面的代码中,我认为您正在尝试从 localhost 连接到 AWS Elastic Service。为此,您需要执行一些步骤。请参阅此答案以获取更多信息。 Link

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-28
      • 1970-01-01
      • 2013-08-13
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多