码迷,mamicode.com
首页 > 系统相关 > 详细

Memcachedf——分布式缓存

时间:2016-05-05 11:04:04      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:

       下载文件:https://sourceforge.net/projects/memcacheddotnet/ 

       将Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll 等放到bin目录

       引用Memcached.ClientLibrary.dll

      程序实例:

       

using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memcached随练
{
    class Program
    {
        static void Main(string[] args)
        {
            //分布Memcachedf服务IP 端口
            string[] servers = { "127.0.0.1:11211", "192.168.202.128:11211" };

            //初始化池
            SockIOPool pool = SockIOPool.GetInstance();
            pool.SetServers(servers);
            pool.InitConnections = 3;
            pool.MinConnections = 3;
            pool.MaxConnections = 5;
            pool.SocketConnectTimeout = 1000;
            pool.SocketTimeout = 3000;
            pool.MaintenanceSleep = 30;
            pool.Failover = true;
            pool.Nagle = false;
            pool.Initialize();
            //客户端实例
            MemcachedClient mc = new Memcached.ClientLibrary.MemcachedClient();
            mc.EnableCompression = false;
            mc.Add("aaa", "shit");//添加一个值
            mc.Add("bbb", "hello", DateTime.Now.AddSeconds(10));//设置过期时间
            mc.Delete("aaa");//删除指定值
            mc.Get("aaa");
            Console.WriteLine(mc.Get("bbb"));

        }
    }
}

 

Memcachedf——分布式缓存

标签:

原文地址:http://www.cnblogs.com/shuai7boy/p/5460963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!