Redis. NET open-source component Beetle. Redis

Source: Internet
Author: User

Beetle. redis is an open-source Redis Client.. net component, which provides a very simple operation method for developers to easily access Redis, and supports json and protobuf data formats. the default access method based on the connection pool allows developers to access redis in a concise and efficient manner, without having to worry about complicated things such as thread and connection synchronization. the Configuration component must be configured before use. It is mainly used to describe the information for accessing Redis, which is the read/write service table column. <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> Configure the read/write service addresses respectively, the number of connections enabled by default is 9, and the number of accesses to the database is 0. You can configure multiple redis service information according to the actual application needs. components are easy to use. You do not need to define the connection information like other redis client components before using them, by default, the component automatically uses the redisClientSection configuration environment to operate the corresponding Redis service. string Get/Set StringKey key = "HENRY"; string Remark = "henryfan gz cn 18 henryfan@msn.com 28304340"; key. set (Remark); Assert. areEqual (Remark, key. get <string> (); Json Get/Set JsonKey rk = "henry_json"; UserBase ub = new UserBase (); ub. name = "henryfan"; ub. city = "gz"; ub. counrty = "cn"; ub. age = 10; rk. set (ub); Protobuf Get/Set 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 <UserBase> (). name); List [TestMethod] public void LST_POP_PUSH () {ProtobufList <UserBase> 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 <UserBase> 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 <UserBase> 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 <UserBase> 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 <UserBase> 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");} MapSet [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 <object> data = map. get <UserBase, Contact> (); 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> (); contact = map. get <Contact> (); 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 <object> data = map. get <UserBase, Contact> (); Assert. areEqual (null, data [0]); Assert. areEqual (null, data [1]);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.