static void Main(string[] args) { //分布Memcachedf服务IP 端口 string[] servers = { "10.12.11.44: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("keyddd", "sssssssss"); mc.Add("ssss", "dddd", DateTime.Now.AddDays(1)); //mc.Delete() //mc.Set() }
static void Main(string[] args) { //分布Memcachedf服务IP 端口 string[] servers = { "192.168.1.9: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("key1", "This is my value", DateTime.Now.AddMinutes(20)); }
static void Main(string[] args) { //分布Memcachedf服务IP 端口 string[] servers = { "192.168.1.100:11211", "192.168.1.2: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("Key", "黑马8期大鹏"); Console.WriteLine("Ok"); // mc.Add("ssss", "dddd", DateTime.Now.AddDays(1)); }
static void Main(string[] args) { //分布Memcachedf服务IP 端口 string[] servers = { "192.168.1.105: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; string key1 = "key-1"; string value1 = "value1"; mc.Add(key1, value1); Console.WriteLine(key1 + " " + mc.Get(key1)); string key2 = "key5"; string value2 = "value5"; mc.Add(key2, value2); Console.WriteLine(key2 + " " + mc.Get(key2)); //var userInfos = UserInfoService.GetEntities(u => u.UName == "admin" && u.Pwd == "123456" && u.DelFlag == "0").FirstOrDefault(); //var userinfo ={string username="******",string wd="123456"} mc.Add("d4491076-3a6b-4f47-9515-a2bb64e7869c", "11111"); Console.WriteLine(mc.Get("d4491076-3a6b-4f47-9515-a2bb64e7869c")); }
public static void Add(string key, object value, DateTime ExpireDate) { if (mc.KeyExists(key)) { mc.Set(key, value, ExpireDate); } else { mc.Add(key, value, ExpireDate); } }
/// <summary> /// 插入或替换缓存内的键值 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="strKey"></param> /// <param name="value"></param> /// <param name="ExpiryTime"></param> /// <returns></returns> public static bool AddOrReplaceCache <T>(string strKey, T value, DateTime ExpiryTime) { if (MC.KeyExists(strKey) != true) { return(MC.Add <T>(strKey, value, ExpiryTime)); } else { return(MC.Replace <T>(strKey, value, ExpiryTime)); } }
public BlipMessageServerHandler ( string[] servers, string rootQueueId ) { this.rootQueueId = rootQueueId; SockIOPool pool = SockIOPool.GetInstance("bucker-queue-server"); 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(); mc = new MemcachedClient(); mc.PoolName = "bucker-queue-server"; mc.EnableCompression = false; mc.Add(rootQueueId, String.Empty); }
static void Main(string[] args) { string[] servers = { "127.0.0.1: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("gct", "aiyangying"); //mc.Delete("gct"); mc.Add("smj", "hhh", DateTime.Now.AddDays(1)); }