需要帮助memcache [英] Need help for memcache

查看:135
本文介绍了需要帮助memcache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在使用Memcache的以下代码,但它没有存储任何数据,请指教。



Hello,

I am working with below code for Memcache but it is not storing any data, please advise.

using (MemcachedClient client = new MemcachedClient())
            {
                client.Store(StoreMode.Set, "KeyData1", "KeyDataValue1");

                string value = client.Get<string>("KeyData1");

            }
        

            ///////////////////////////////////

            MemcachedClient mcCacheItems;
            MemcachedClientConfiguration memCacheconfig = new MemcachedClientConfiguration();
            {
                string host = "XXX";
                int port = 11211;
                memCacheconfig.AddServer(host, port);
                memCacheconfig.Protocol = MemcachedProtocol.Binary;

                mcCacheItems = new MemcachedClient(memCacheconfig);

                mcCacheItems.Store(StoreMode.Add, "KeyData2", "KeyDataValue2");
                string Value1 = Convert.ToString(mcCacheItems.Get("KeyData2"));
            }





我的尝试:





What I have tried:

using (MemcachedClient client = new MemcachedClient())
            {
                client.Store(StoreMode.Set, "KeyData1", "KeyDataValue1");

                string value = client.Get<string>("KeyData1");

            }

推荐答案

您正在创建客户端使用块在内的对象,因此只要该块完成,对象就会被释放并且不再存在。 对象也是如此。您需要在.NET中研究对象范围和生命周期的主题。
You are creating your client object inside a using block, so as soon as that block completes the object is disposed and no longer exists. The same is true of the value object. You need to study the subject of object scope and lifetime in .NET.


这篇关于需要帮助memcache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆