.net MemCache 入门到简单使用链接汇总

 

Memcached安装使用请参考:http://www.cnblogs.com/zjneter/archive/2007/07/19/822780.html

 

封装方法: 缓存应用--Memcached分布式缓存简介(二)

总结:如果想调用已存的Memcached 必须保证 servers 中的地址必须一样才能得到指定的缓存  这是在第一个应用程序中设置的Memcached

SockIOPool pool = SockIOPool.GetInstance();
            string[] servers = {"127.0.0.1:11211"};
            pool.SetServers(servers);
            pool.MinConnections = 3;
            pool.MaxConnections = 5;
            pool.InitConnections = 3;
            pool.SocketConnectTimeout = 5000;
            pool.Initialize();

            MemcachedClient client = new MemcachedClient();
            client.EnableCompression = false;
            Console.WriteLine("------------------------Memcached Set 设置值--------------------------");
            client.Set("key1", "value1");
            Console.WriteLine(client.Get("key1"));
            Console.WriteLine("------------------------Memcached Add 设置值--------------------------");
            client.Add("key2", "value2");
            Console.WriteLine(client.Get("key2"));
            client.Set("key2", "value1 value2");
            Console.WriteLine(client.Get("key2"));
            Console.WriteLine("------------------------Memcached Replace 设置值--------------------------");
            client.Replace("key2", "value3");
            Console.WriteLine(client.Get("key2"));

            Console.WriteLine("------------------------Memcached 键值是否存在--------------------------");
            if (client.KeyExists("key2"))
            {
                Console.WriteLine("key2 Exists");
            }
            if (client.KeyExists("eee") == false)
            {
                Console.WriteLine("键eee不存在");
            }

            Console.WriteLine("------------------------Memcached 删除数据--------------------------");
            client.Add("key4", "value4");
            Console.WriteLine("key4==>" + client.Get("key4"));
            client.Delete("key4");
            if (!client.KeyExists("key4"))
            {
                Console.WriteLine("key4 已删除");
            }

这是在另一个应用程序中得到指定的缓存对象

SockIOPool pool = SockIOPool.GetInstance();
            string[] servers = { "127.0.0.1:11211" };
            pool.SetServers(servers);
            pool.MinConnections = 3;
            pool.MaxConnections = 5;
            pool.InitConnections = 3;
            pool.SocketConnectTimeout = 5000;
            pool.Initialize();
//从该指定服务器中得到以保存的缓存对象
MemcachedClient client = new MemcachedClient();
Console.WriteLine(client.Get("key1"));
Console.WriteLine(client.Get("key2"));
Console.ReadKey();

 

 

该文章仅仅只是个人今天刚刚看到的并汇总的 有好多地方是摘取其他大牛的链接 第一次随笔  希望看到的大牛们不喜勿喷 

posted on 2015-12-18 10:51  LKit  阅读(219)  评论(0编辑  收藏  举报