Redis .NET开源组件Beetle.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]);
}
上一篇: JSTL和EL介绍
下一篇: C#利用性能计数器监控网络状态
推荐阅读
-
.NET中开源文档操作组件DocX的介绍与使用
-
详解免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)
-
详解最好的.NET开源免费ZIP库DotNetZip(.NET组件介绍之三)
-
详解免费开源的.NET多类型文件解压缩组件SharpZipLib(.NET组件介绍之七)
-
详解免费开源的DotNet二维码操作组件ThoughtWorks.QRCode(.NET组件介绍之四)
-
.NET 开源配置组件 AgileConfig的使用简介
-
详解开源免费且稳定实用的.NET PDF打印组件itextSharp(.NET组件介绍之八)
-
老牌开源Office操作组件NPOI现已支持.NET Core
-
.NET定时任务执行管理器开源组件–FluentScheduler,可以在web应用程序里面使用
-
日志组件Log2Net的介绍和使用(附开源地址)