This article is a mirror article of machine translation, please click here to jump to the original article.

View: 27351|Reply: 1

[Redis] Redis . .NET open-source component Beetle.Redis

[Copy link]
Posted on 12/29/2015 11:58:16 AM | | | |
Beetle.Redis is an open-source Redis Client for .net component that provides a very simple way for developers to easily access Redis, while providing data format support for json and protobuf. The default access based on connection pools allows developers to access Redis succinctly and efficiently without having to worry about a series of complex things such as threading and connection synchronization.
disposition

  1. <configSections>
  2.     <section name="redisClientSection" type="Beetle.Redis.RedisClientSection, Beetle.Redis, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
  3.   </configSections>
  4.   <redisClientSection dB="0"  xmlns="urn:Beetle.Redis">
  5.     <writes>
  6.       <add host="192.168.0.105" connections="9"/>
  7.     </writes>
  8.     <reads>
  9.       <add host="192.168.0.105" connections="9"/>
  10.     </reads>
  11.   </redisClientSection>
Copy code

The above configurations are the read/write service addresses, and the default number of connections is 9, and the database access is 0. Multiple redis service information can be configured according to the needs of the actual application.


The use of the component is very simple, there is no need to define the connection information like other redis client components before use, and the component will automatically use the configuration environment of redisClientSection to operate the corresponding Redis service by default.


String Get/Set


  1. StringKey key = "HENRY";
  2.             string Remark = "henryfan gz cn 18 [email]henryfan@msn.com[/email] 28304340";
  3.             key.Set(Remark);
  4.             Assert.AreEqual(Remark, key.Get());
Copy code
Json Get/Set


  1. JsonKey rk = "henry_json";
  2.             UserBase ub = new UserBase();
  3.             ub.Name = "henryfan";
  4.             ub.City = "gz";
  5.             ub.Counrty = "cn";
  6.             ub.Age = 10;
  7.             rk.Set(ub);
  8.             Assert.AreEqual(ub.Name, rk.Get().Name);
Copy code
Protobuf Get/Set


  1. ProtobufKey rk = "henry_protobuf";
  2.             UserBase ub = new UserBase();
  3.             ub.Name = "henryfan";
  4.             ub.City = "gz";
  5.             ub.Counrty = "cn";
  6.             ub.Age = 10;
  7.             rk.Set(ub);
  8.             Assert.AreEqual(ub.Name, rk.Get().Name);
Copy code


List


  1. [TestMethod]
  2.         public void LST_POP_PUSH()
  3.         {
  4.             ProtobufList lst = "USERS";
  5.             lst.Push(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  6.             Assert.AreEqual("henry", lst.Pop().Name);
  7.         }
  8.         [TestMethod]
  9.         public void LST_REMOVE_ADD()
  10.         {
  11.             ProtobufList lst = "USERS";
  12.             lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  13.             lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
  14.             Assert.AreEqual("bbq", lst.Remove().Name);
  15.         }
  16.         [TestMethod]
  17.         public void LST_Length()
  18.         {
  19.             ProtobufList lst = "USERS";
  20.             lst.Clear();
  21.             lst.Add(new UserBase { Name = "henry", Age = 18, City = "gz", Counrty = "cn" });
  22.             lst.Add(new UserBase { Name = "bbq", Age = 18, City = "gz", Counrty = "cn" });
  23.             Assert.AreEqual(lst.Count(), 2);
  24.         }
  25.         [TestMethod]
  26.         public void LST_Region()
  27.         {
  28.             ProtobufList lst ="USERS";
  29.             lst.Clear();
  30.             for (int i = 0; i < 10; i++)
  31.             {
  32.                 lst.Add(new UserBase { Name = "henry" + i, Age = 18, City = "gz", Counrty = "cn" });
  33.             }
  34.             IList items = lst.Range();
  35.             Assert.AreEqual(items[0].Name, "henry0");
  36.             Assert.AreEqual(items[9].Name, "henry9");
  37.             items = lst.Range(5, 7);
  38.             Assert.AreEqual(items[0].Name, "henry5");
  39.             Assert.AreEqual(items[2].Name, "henry7");
  40.         }
Copy code
MapSet


  1. [TestMethod]
  2.         public void MapSet()
  3.         {

  4.             JsonMapSet map = "HENRY_INFO";
  5.             UserBase ub = new UserBase();
  6.             ub.Name = "henryfan";
  7.             ub.City = "gz";
  8.             ub.Counrty = "cn";
  9.             ub.Age = 10;
  10.             Contact contact = new Contact();
  11.             contact.EMail = "hernyfan@msn.com";
  12.             contact.QQ = "28304340";
  13.             contact.Phone = "13660223497";
  14.             map.Set(ub, contact);
  15.             IList data = map.Get();
  16.             Assert.AreEqual(ub.Name, ((UserBase)data[0]).Name);
  17.             Assert.AreEqual(contact.Phone, ((Contact)data[1]).Phone);

  18.         }
  19.         [TestMethod]
  20.         public void MapSetdRemove()
  21.         {
  22.             JsonMapSet map = "HENRY_INFO";
  23.             UserBase ub = new UserBase();
  24.             ub.Name = "henryfan";
  25.             ub.City = "gz";
  26.             ub.Counrty = "cn";
  27.             ub.Age = 10;
  28.             Contact contact = new Contact();
  29.             contact.EMail = "hernyfan@msn.com";
  30.             contact.QQ = "28304340";
  31.             contact.Phone = "13660223497";
  32.             map.Set(ub, contact);
  33.             map.Remove();
  34.             contact = map.Get();
  35.             Assert.AreEqual(null, contact);

  36.         }
  37.         [TestMethod]
  38.         public void MapSetClear()
  39.         {
  40.             JsonMapSet map = "HENRY_INFO";
  41.             UserBase ub = new UserBase();
  42.             ub.Name = "henryfan";
  43.             ub.City = "gz";
  44.             ub.Counrty = "cn";
  45.             ub.Age = 10;
  46.             Contact contact = new Contact();
  47.             contact.EMail = "hernyfan@msn.com";
  48.             contact.QQ = "28304340";
  49.             contact.Phone = "13660223497";
  50.             map.Set(ub, contact);
  51.             map.Clear();
  52.             IList data = map.Get();
  53.             Assert.AreEqual(null, data[0]);
  54.             Assert.AreEqual(null, data[1]);
  55.         }
Copy code


performance

Sample
Download

Beetle.Redis.0.6.6.5.rar (244.2 KB, Number of downloads: 1)




Previous:sessionState configuration scheme cookieless
Next:5 Things You Must Know Before Using Redis
Posted on 9/22/2021 8:25:08 PM |
Learn to learn...
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com