Unable to get Enyim.Caching MemcachedClient to work with Couchbase

不问归期 提交于 2019-12-11 19:27:51

问题


I realize that Couchbase provides a client to their memcached server, but I'm trying to get the enyim.caching client to work.

Here's my trivial c# code that uses the Couchbase client (which works) and then pretty much the same thing with the enyim MemcachedClient:

class Program
{
    static void Main(string[] args)
    {
        var client = new CouchbaseClient();

        client.Store(StoreMode.Set, "somekey", "somevalue");

        var somevalue = client.Get<string>("somekey");

        Console.WriteLine(somevalue);
        Console.ReadLine();

        var mclient = new MemcachedClient();
        mclient.Store(StoreMode.Set, "Hello", "World");
        var myVal = mclient.Get<string>("Hello");
        Console.WriteLine(myVal);
        Console.ReadLine();
    }
}

Here's my app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
      <section name="couchbase" type="Couchbase.Configuration.CouchbaseClientSection, Couchbase"/>
      <sectionGroup name="enyim.com">
        <section name="memcached" type="Enyim.Caching.Configuration.MemcachedClientSection, Enyim.Caching" />      
      </sectionGroup>
    </configSections>
    <couchbase>
      <servers bucket="default" bucketPassword="myPassword">
        <add uri="http://127.0.0.1:8091/pools"/>
      </servers>
    </couchbase>
<enyim.com>
  <memcached>
    <servers>
      <add address="127.0.0.1" port="8091" />
    </servers>
    <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:10:00" deadTimeout="00:02:00" />
    <authentication type="Enyim.Caching.Memcached.PlainTextAuthenticator, Enyim.Caching" zone="" userName="Administrator" password="myPassword" />
  </memcached>
</enyim.com>
<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>  
</configuration>

When I step through the code, the Couchbase client appears to work fine. The Get method returns "somevalue" as expected. The code also happily steps through the MemcachedClient code, but when I step through the Store method, it hangs for 10 seconds (I think that's the timeout) and then the myVal value returns as null. No errors are thrown.

I suspect the problem revolves around the zone value in the authentication node for memcached in the config. In the DemoApp code that is in the enyim.caching source code (retrieved from Github), zone is never specified, but enyim throws an error if the zone isn't provided - i.e. the DemoApp doesn't work as is because zone isn't provided.

I'm not sure this is the problem, but I do know that I can't leave zone out, but I don't know what to use for that value. I've seen an example where 'AUTHZ' was used, but that doesn't seem to make any difference.

Does anyone see what I'm doing wrong here? Any help is appreciated! :)


回答1:


Ok - I figured out what was going on. I went back into the Couchbase Console and noticed that my only databucket was of type Couchbase. So, I created a new databucket of type Memcached. I noticed that this bucket type required no authentication. I did have to give it a new port.

Once I made the minimal changes to my config file, the enyim.caching MemcachedClient code worked perfectly!

Here's what my new enyim.caching config stuff looks like now:

<enyim.com>
  <memcached>
    <servers>
      <add address="127.0.0.1" port="8095" />
    </servers>
    <socketPool minPoolSize="10" maxPoolSize="100" connectionTimeout="00:10:00" deadTimeout="00:02:00" />
  </memcached>
</enyim.com>

I will mark this answer as the solution as soon as I'm able. Hopefully this may help someone from making my knuckleheaded mistake. :)

UPDATE:

Take a look in the comments for another solution provided by John Zablocki. Thanks John!



来源:https://stackoverflow.com/questions/12677445/unable-to-get-enyim-caching-memcachedclient-to-work-with-couchbase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!