문제

var config = new MemcachedClientConfiguration();
config.Protocol = MemcachedProtocol.Binary;
config.AddServer(server[0],int.Parse(server[1]));


var mc = new MemcachedClient(config);

var finish = mc.Store(StoreMode.Set, key, value,TimeSpan.FromSeconds((double)60000));
if(finish)
{
var obj=mc.Get(key);
Debug.Assert(obj==null,"obj is null.")
}

The result(obj) always returns null, why?

If expire is set to TimeSpan.MaxValue it is okay.

도움이 되었습니까?

해결책

The code looks fine. I've run a test for this and it passes

     [Test]
     public void Should_get_object()
     {
        const string key = "1";
        const string value = "6";
        var mc = new MemcachedClient();

        var finish = mc.Store(Enyim.Caching.Memcached.StoreMode.Set, 
                              key, value, TimeSpan.FromSeconds((double)60000));

         if(finish)
         {
            var obj=mc.Get(key);
            Assert.That(obj!=null,"obj is null.");
         }
    }

Thus I'd suspect the configuration, here is the one I've used for comparison

<enyim.com>
    <memcached>
      <servers>
        <add address="127.0.0.1" port="11211"/>
      </servers>
      <socketPool minPoolSize="10" maxPoolSize="100" 
                  connectionTimeout="00:00:10" deadTimeout="00:02:00"/>
    </memcached>
  </enyim.com>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top