标签:log info base scribe 添加 gap date span user
ConfigurationOptions op = new ConfigurationOptions(); op.EndPoints.Add("192.168.1.202", 6379); op.Password = "mdsd"; op.AbortOnConnectFail = false; ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(op);
第二种,使用用字符串
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("192.168.1.202:6379,password=mdsd"); IDatabase db = redis.GetDatabase();
随便写点用例
//设置数据对象 //db.StringSet("User", "{Name:\"TOM\"}"); //添加数据对象 //db.StringAppend("User", ",{Name:\"JACK\"}"); //取得数据对象 //string user = db.StringGet("User"); //Console.WriteLine(user); db.StringSet("User", "{Name:\"TOM\"}", new TimeSpan(1, 0, 0)); db.ListLeftPush("userinfo", "{Name:\"LALI\"}"); db.ListSetByIndex("userinfo", 0, "{Name:\"TOM\"}"); db.ListLeftPush("userinfo", "{Name:\"LALI\"}"); db.ListRightPush("userinfo", "{Name:\"JACK\"}"); var len = db.ListLength("userinfo"); Console.WriteLine("data leng:" + len.ToString()); for (int i = 0; i < len; i++) { Console.WriteLine(i.ToString() + ":" + db.ListGetByIndex("userinfo", i)); } db.KeyDelete("userinfo");
订阅和发布
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(op); ISubscriber sub = redis.GetSubscriber(); sub.Subscribe("*", (channel, message) => { Console.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss fff ") + (string)message); }); sub.Publish("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello"); //sub.PublishAsync("messages", "hello");
标签:log info base scribe 添加 gap date span user
原文地址:http://www.cnblogs.com/mapy/p/7724361.html