【问题标题】:Amazon's AWS elasticache - c# example亚马逊的 AWS elasticache - c# 示例
【发布时间】:2017-06-14 22:49:11
【问题描述】:

有没有人有使用 C# 连接到 AWS elasticache (memcached) 集群的示例代码?

我找到了 this 示例,但它似乎有点旧(该库来自 2010 年)。 This github library 可能有效。没有太多的例子。

谢谢,

【问题讨论】:

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


    【解决方案1】:

    Richard Seroter 的这个 pluralsight 视频使用它。

    步骤:

    添加以下 nuget 包:EnyimMemCached

    然后将此添加到您的网络配置中的 configSections 节点:

    <sectionGroup name="enyim.com">
          <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching"/>
        </sectionGroup>
    

    然后在system.web节点下面添加这个(所以它是system.web的兄弟节点)。请务必用您的 elasticache 端点替换 url 和端口:

    <enyim.com>
        <memcached>
          <servers>
            <add address="...your elasticache url here...." port="your port here..."></add>
          </servers>
        </memcached>
      </enyim.com>
    

    然后在我看来,我调用了设置缓存值并将其读出。它仅在发布并在 AWS 上运行时才有效。(在本地不工作):

     public ActionResult Index()
            {
                var client = new MemcachedClient();
    
                string myCacheKey = "MyCacheKey";
                client.Store(Enyim.Caching.Memcached.StoreMode.Set, myCacheKey, "If you see this it worked.");  // set the cache.
                string myCachedString = client.Get<string>(myCacheKey);
    
                ViewBag.MyCache = myCachedString ?? "**** SORRY,  DIDN'T WORK..***..";
                return View();
    
            }
    

    希望这对某人有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-08
      • 2011-12-29
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      相关资源
      最近更新 更多