Beetle.redis是一款開源的Redis Client for .net組件,它提供非常簡便的操作方式可以讓開發(fā)人員輕松地訪問Redis,同時(shí)提供json和protobuf的數(shù)據(jù)格式支持.基于連接池的默認(rèn)訪問方式可以讓開發(fā)人員簡潔高效地訪問redis同時(shí),而不必關(guān)心線程和連接同步等一系列復(fù)雜的事情.
成都創(chuàng)新互聯(lián)公司專注于企業(yè)網(wǎng)絡(luò)營銷推廣、網(wǎng)站重做改版、神農(nóng)架林區(qū)網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、成都做商城網(wǎng)站、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為神農(nóng)架林區(qū)等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
組件在使用前要進(jìn)行配置,主要用于描述訪問Redis的信息,分別是讀寫服務(wù)表列.
<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>以上分別配置讀/寫服務(wù)地址,默認(rèn)開啟的連接數(shù)是9個(gè),訪問數(shù)據(jù)庫是0;根據(jù)實(shí)際應(yīng)用的需要讀/寫都可以配置多個(gè)redis服務(wù)信息.
組件的使用非常簡單,在使用前并不需要象其他redis client組件一樣定義連接信息,組件在缺省的情況下會自動使用 redisClientSection的配置環(huán)境去操作相應(yīng)的Redis服務(wù).
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); Assert.AreEqual(ub.Name, rk.Get<UserBase>().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<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]); }
Beetle.Redis 0.6
NorthWind Sample
Source Project
當(dāng)前題目:RedisFor.NET開源組件Beetle.Redis
本文URL:http://bm7419.com/article26/pcgojg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、響應(yīng)式網(wǎng)站、定制開發(fā)、企業(yè)建站、網(wǎng)站改版、建站公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)