当前位置: 移动技术网 > IT编程>开发语言>.net > Redis .NET开源组件Beetle.Redis

Redis .NET开源组件Beetle.Redis

2018年11月01日  | 移动技术网IT编程  | 我要评论

天魔神谭无弹窗,sjk800.mdb,吉赛尔近卫兵的徽章

beetle.redis是一款开源的redis client for .net,它提供非常简便的操作方式可以让开发人员轻松地访问redis,同时提供json和protobuf的数据格式支持.基于连接池的默认访问方式可以让开发人员简洁高效地访问redis同时,而不必关心线程和连接同步等一系列复杂的事情.

 

配置

 

组件在使用前要进行配置,主要用于描述访问redis的信息,分别是读写服务表列.

 

 

  <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>

 

以上分别配置读/写服务地址,默认开启的连接数是9个,访问是0;根据实际应用的需要读/写都可以配置多个redis服务信息.

 

使用

 

组件的使用非常简单,在使用前并不需要象其他redis client组件一样定义连接信息,组件在缺省的情况下会自动使用 redisclientsection的配置环境去操作相应的redis服务.

 

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]);

        }

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网