|
Beetle.Redis yra atvirojo kodo Redis klientas, skirtas .net komponentui, kuris suteikia labai paprastą būdą kūrėjams lengvai pasiekti Redis, tuo pačiu palaikant duomenų formatą json ir protobuf. Numatytoji prieiga, pagrįsta ryšių telkiniais, leidžia kūrėjams glaustai ir efektyviai pasiekti Redis, nesijaudinant dėl daugybės sudėtingų dalykų, tokių kaip gijų ir ryšio sinchronizavimas. Disponavimo
- <configSections>
- <section name="redisClientSection" type="Beetle.Redis.RedisClientSection, Beetle.Redis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
- </configSections>
- <redisClientSection dB="0" xmlns="urn:Beetle.Redis">
- <writes>
- <add host="192.168.0.105" connections="9"/>
- </writes>
- <reads>
- <add host="192.168.0.105" connections="9"/>
- </reads>
- </redisClientSection>
Kopijuoti kodą
Aukščiau pateiktos konfigūracijos yra skaitymo/rašymo tarnybos adresai, numatytasis ryšių skaičius yra 9, o prieiga prie duomenų bazės yra 0. Kelių redis paslaugų informaciją galima sukonfigūruoti pagal faktinės programos poreikius.
Komponento naudojimas yra labai paprastas, prieš naudojimą nereikia apibrėžti ryšio informacijos, kaip ir kitų "Redis" kliento komponentų, o komponentas automatiškai naudos "redisClientSection" konfigūracijos aplinką, kad pagal numatytuosius nustatymus veiktų atitinkama "Redis" paslauga.
Eilutės gavimas/nustatymas
- StringKey key = "HENRY";
- string Remark = "henryfan gz cn 18 [email]henryfan@msn.com[/email] 28304340";
- key.Set(Remark);
- Assert.AreEqual(Remark, key.Get());
Kopijuoti kodą Json Gauti / Nustatyti
- JsonKey rk = "henry_json";
- UserBase ub = new UserBase();
- ub.Name = "henryfan";
- ub.City = "gz";
- ub.Counrty = "cn";
- ub.Age = 10;
- rk.Set(ub);
- Assert.AreEqual(ub.Name, rk.Get().Name);
Kopijuoti kodą Protobuf Gauti / Nustatyti
- ProtobufKey rk = "henry_protobuf";
- UserBase ub = new UserBase();
- ub.Name = "henryfan";
- ub.City = "gz";
- ub.Counrty = "cn";
- ub.Age = 10;
- rk.Set(ub);
- Assert.AreEqual(ub.Name, rk.Get().Name);
Kopijuoti kodą
Sąrašas
- [TestMethod]
- public void LST_POP_PUSH()
- {
- ProtobufList lst = "USERS";
- lst.Push(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
- Assert.AreEqual("henry", lst.Pop().Name);
- }
- [TestMethod]
- public void LST_REMOVE_ADD()
- {
- ProtobufList lst = "USERS";
- lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
- lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
- Assert.AreEqual("bbq", lst.Remove().Name);
- }
- [TestMethod]
- public void LST_Length()
- {
- ProtobufList lst = "USERS";
- lst.Clear();
- lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
- lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
- Assert.AreEqual(lst.Count(), 2);
- }
- [TestMethod]
- public void LST_Region()
- {
- ProtobufList lst ="USERS";
- lst.Clear();
- for (int i = 0; i < 10; i++)
- {
- lst.Add(new UserBase { Name = "henry" + i, Age = 18, City = "gz", Counrty = "cn" });
- }
- IList items = lst.Range();
- Assert.AreEqual(items[0].Name, "henry0");
- Assert.AreEqual(items[9].Name, "henry9");
- items = lst.Range(5, 7);
- Assert.AreEqual(items[0].Name, "henry5");
- Assert.AreEqual(items[2].Name, "henry7");
- }
Kopijuoti kodą Žemėlapių rinkinys
- [TestMethod]
- public void MapSet()
- {
- JsonMapSet map = "HENRY_INFO";
- UserBase ub = new UserBase();
- ub.Name = "henryfan";
- ub.City = "gz";
- ub.Counrty = "cn";
- ub.Age = 10;
- Contact contact = new Contact();
- contact.EMail = "hernyfan@msn.com";
- contact.QQ = "28304340";
- contact.Phone = "13660223497";
- map.Set(ub, contact);
- IList data = map.Get();
- Assert.AreEqual(ub.Name, ((UserBase)data[0]).Name);
- Assert.AreEqual(contact.Phone, ((Contact)data[1]).Phone);
- }
- [TestMethod]
- public void MapSetdRemove()
- {
- JsonMapSet map = "HENRY_INFO";
- UserBase ub = new UserBase();
- ub.Name = "henryfan";
- ub.City = "gz";
- ub.Counrty = "cn";
- ub.Age = 10;
- Contact contact = new Contact();
- contact.EMail = "hernyfan@msn.com";
- contact.QQ = "28304340";
- contact.Phone = "13660223497";
- map.Set(ub, contact);
- map.Remove();
- contact = map.Get();
- Assert.AreEqual(null, contact);
- }
- [TestMethod]
- public void MapSetClear()
- {
- JsonMapSet map = "HENRY_INFO";
- UserBase ub = new UserBase();
- ub.Name = "henryfan";
- ub.City = "gz";
- ub.Counrty = "cn";
- ub.Age = 10;
- Contact contact = new Contact();
- contact.EMail = "hernyfan@msn.com";
- contact.QQ = "28304340";
- contact.Phone = "13660223497";
- map.Set(ub, contact);
- map.Clear();
- IList data = map.Get();
- Assert.AreEqual(null, data[0]);
- Assert.AreEqual(null, data[1]);
- }
Kopijuoti kodą
Veiklos
PavyzdysAtsisiųsti
Beetle.Redis.0.6.6.5.rar
(244.2 KB, Atsisiuntimų skaičius: 1)
|