我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

RedisFor.NET开源组件Beetle.Redis-创新互联

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

创新互联建站是一家专注于网站设计、网站制作与策划设计,邱县网站建设哪家好?创新互联建站做网站,专注于网站建设10年,网设计领域的专业建站公司;建站业务涵盖:邱县等地区。邱县做网站价格咨询:18980820575

配置

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


  

以上分别配置读/写服务地址,默认开启的连接数是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());

  • 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);
    Assert.AreEqual(ub.Name, rk.Get().Name);

  • 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().Name);

  • List

    [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");
    }

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

    性能

    Redis For .NET开源组件Beetle.Redis

    Sample

    Redis For .NET开源组件Beetle.Redis

    下载

    Beetle.Redis 0.6

    NorthWind Sample

    Source Project

    另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


    网站栏目:RedisFor.NET开源组件Beetle.Redis-创新互联
    标题路径:http://shouzuofang.com/article/dhpgcd.html