【问题标题】:How to use enyim memcached client with amazon elasticache in c#如何在 c# 中将 enyim memcached 客户端与亚马逊 elasticache 一起使用
【发布时间】:2015-08-25 07:07:48
【问题描述】:

我在 Amazon ElastiCache 上创建了一个缓存集群。它给了我一个端点地址。 现在我想将数据存储在 Amazon ElastiCache 中。为此,我正在使用 enyim memcached 客户端。

服务器报错为;

Enyim.Caching.Memcached.ServerPool 的类型初始化程序抛出错误

我的配置是这样的;

<enyim.com>
    <memcached>
      <servers>
        <!-- put your own server(s) here-->
        <add address="<MyendPointAddress" port="11211" />
      </servers>
      <socketPool minPoolSize="10" maxPoolSize="100"
      connectionTimeout="00:01:10" deadTimeout="00:05:00" />
    </memcached>
  </enyim.com>

在 C# 中我写过这样的东西;

using (MemcachedClient client = new MemcachedClient())
            {
                client.Store(Enyim.Caching.Memcached.StoreMode.Add, key, value);
                var l = client.Get(key);
            }

当我使用本地主机时,代码不会抛出任何错误,但不会存储任何内容。

编辑: 现在我已经转移到 BeIT memcached 客户端。它运行良好,但返回 null 作为 Get() 请求的输出。

【问题讨论】:

    标签: c# caching memcached amazon-elasticache enyim.caching


    【解决方案1】:

    不要使用配置节点,ElastiCache 设置一个配置端点,您可以将其与他们拥有的 Java 或 PHP 库一起使用,或者滚动您自己的来获取节点。他们在开发人员文档中记录了如何使用此配置节点的大部分内容。

    这样做的好处是,无论何时添加或删除一个节点,您都不必重新配置您的应用程序,您只需询问 memcached 配置节点即可。

    如果您不想这样做,那么只需转到节点并将它们添加到您的配置中,就像您只有一堆 Memcached 服务器一样。

    【讨论】:

      【解决方案2】:

      这个问题已经有一段时间了,但以防其他人面临同样的问题。

      enyim.memcached 配置需要是这样的;

      <configSections>
          <section name="clusterclient" type="Amazon.ElastiCacheCluster.ClusterConfigSettings, Amazon.ElastiCacheCluster" />    
      </configSections>
      <clusterclient>
          <endpoint hostname="[Add your ElastiCache cluster endpoint here]" port="11211" />
          <node nodeTries="5" nodeDelay="1000" />
          <poller intervalDelay="60000" />
      </clusterclient>
      

      然后您可以通过 C# 代码访问 Elasticache;

      new MemcachedClient(new ElastiCacheClusterConfig()).Store(key, value, expireAt)
      new MemcachedClient(new ElastiCacheClusterConfig()).Get(key)
      

      这是一个完整的例子; http://www.omidmufeed.com/how-to-use-elasticache-memcached-or-runtime-caching-in-c/

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-18
      • 2014-01-19
      • 1970-01-01
      • 1970-01-01
      • 2011-08-14
      相关资源
      最近更新 更多