How to use enyim memcached client with amazon elasticache in c#
I have created a cache cluster on Amazon ElastiCache. It has given me an endpoint address. Now I want to store the data in Amazon ElastiCache. For that I am making use of enyim memcached client.
The server gives an error as;
Type initializer for Enyim.Caching.Memcached.ServerPool threw an error
My config looks like this;
<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>
In C# I have written something like this;
using (MemcachedClient client = new MemcachedClient())
{
client.Store(Enyim.Caching.Memcached.StoreMode.Add, key, value);
var l = client.Get(key);
}
When I use local host, the code doesn't throw any error, but doesn't store anything.
Edit: Now I have shifted to BeIT memcached client. It runs fine, however returns null as output for Get() requests.
Dont use the confiugration nodes, ElastiCache sets up a config end point that you can use with Java or PHP libraries they have or roll your own to get the nodes. They document most of how to use this configuration node on the developer docs.
The benefit of this is that anytime a node is added or deleted you do not have to reconfigure your app, you can just interrogate the memcached configuration node.
If you don't want to do this, then just go to the nodes and add them to your configuration as you would if you just had a bunch of Memcached servers.
It has been a while since this question, but in case other people are facing the same issue.
The enyim.memcached config need be like this;
<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>
You can then access Elasticache via C# code;
new MemcachedClient(new ElastiCacheClusterConfig()).Store(key, value, expireAt)
new MemcachedClient(new ElastiCacheClusterConfig()).Get(key)
Here is a full example; http://www.omidmufeed.com/how-to-use-elasticache-memcached-or-runtime-caching-in-c/
链接地址: http://www.djcxy.com/p/54100.html上一篇: 我的缓存守护进程应该在哪里生存?