有人有使用 C# 连接到 AWS elasticache (memcached) 集群的示例代码吗?
我找到了this示例,但看起来有点旧(该库是 2010 年的)。 This github library可能有效。例子并不多。
谢谢
最佳答案
可以使用这个pluralsight理查德·塞罗特的视频。
步骤:
添加以下nuget包:EnyimMemCached
然后将其添加到 Web 配置中的 configSections 节点内部:
<sectionGroup name="enyim.com">
<section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching"/>
</sectionGroup>
然后将其添加到 system.web 节点的下方(因此它是 system.web 的同级节点)。请务必将 url 和端口替换为您的 elasticache 端点:
<enyim.com>
<memcached>
<servers>
<add address="...your elasticache url here...." port="your port here..."></add>
</servers>
</memcached>
</enyim.com>
然后在我的 View 操作中,我调用设置缓存值并将其读出。它仅在发布并在 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();
}
希望这对某人有帮助。
关于c# - 亚马逊的 AWS elasticache - c# 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44555900/