【发布时间】:2017-06-14 22:49:11
【问题描述】:
有没有人有使用 C# 连接到 AWS elasticache (memcached) 集群的示例代码?
我找到了 this 示例,但它似乎有点旧(该库来自 2010 年)。 This github library 可能有效。没有太多的例子。
谢谢,
【问题讨论】:
标签: c# amazon-web-services amazon-ec2 memcached amazon-elasticache
有没有人有使用 C# 连接到 AWS elasticache (memcached) 集群的示例代码?
我找到了 this 示例,但它似乎有点旧(该库来自 2010 年)。 This github library 可能有效。没有太多的例子。
谢谢,
【问题讨论】:
标签: c# amazon-web-services amazon-ec2 memcached amazon-elasticache
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();
}
希望这对某人有帮助。
【讨论】: