WeavingDBC# 實(shí)現(xiàn)的緩存庫
WeavingDB
WeavingDB
為滿足C#項(xiàng)目的特殊使用與簡(jiǎn)單部署,而開發(fā)此WeavingDB。
1.支持K-V方式。支持通配符方式匹配KEYS
2.支持JSON數(shù)據(jù)的條件查詢的內(nèi)存緩存庫。(目前JSON庫部分,創(chuàng)建,清空,插入,批量插入,查詢,有條件刪除,修改)。
3.可以設(shè)置最后一次訪問時(shí)間的過期時(shí)效,例如:A數(shù)據(jù),最后一次訪問是1小時(shí)以前,設(shè)置過期為60分鐘,此時(shí)A數(shù)據(jù)將被清理,如果A數(shù)據(jù)在60分鐘內(nèi)再次被訪問則不清理。也可以設(shè)置永久不過期。
4.JSON庫,需要先創(chuàng)建庫,然后就可以插入數(shù)據(jù)了,數(shù)據(jù)庫表的列為自動(dòng)適應(yīng)。第一次插入的數(shù)據(jù)即為默認(rèn)列,以后插入的數(shù)據(jù),可以增加字段,也可以減少字段(不需要重新建立表)。但是字段類型不能更改,如果原本的列名的類型改變,會(huì)引起類型錯(cuò)誤。如果要改變?cè)凶侄晤愋停荒芮蹇諑旌螅瑥男陆臁?/p>
5.支持KV數(shù)據(jù)的持久化,超時(shí)或Remove后并不會(huì)徹底刪除數(shù)據(jù),而是從內(nèi)存中刪除,如果再次get,則從持久化的內(nèi)容中讀取。
暫不支持主從部署和TABLE數(shù)據(jù)持久化,當(dāng)我想到一個(gè)高效模型,我會(huì)更新這兩類內(nèi)容。
6.數(shù)據(jù)通信部分使用WeavingSocket架構(gòu),通信部分架構(gòu)地址:https://gitee.com/dreamsfly900/universal-Data-Communication-System-for-windows
K-V運(yùn)行效率測(cè)試,萬次讀寫1.8秒,配置SURFACEBOOK 一代 8G 128G
使用說明
K-V操作
DBClient dbc = new DBClient("127.0.0.1", 18989, "admin", "123123");
dbc.open();
dbc.Set("asdasd", "1");
int i = 0;
String str2 = dbc.Get("asdasd");string [] keys= dbc.GetKey("as?asd");//通配符?一個(gè)匹配字符
keys = dbc.GetKey("as*");//通配符* 表示,多個(gè)模糊匹配 dbc.close();
Hashtable ht = new Hashtable();
ht.Add("123123","afasdfasdf");
ht.Add("12312311", "afasdfasdf");
ht.Add("1231231221", "afasaasdfasdf");
ht.Add("123123122199", "afasaasdfasdf");
bool bb= dbc.SetAll<string>(ht);//批量Set
dbc.close();
JSON庫操作
dbc.open();
user u = new user();
bool bbc = dbc.inserttable("ddd", u);
dbc.Createtable("ddd");
bbc= dbc.inserttable("ddd", u);
//每次插入一組數(shù)據(jù)
Listlist = new List();
int i = 0;
while (i < 10000)
{
u = new user();
u.id = i;
list.Add(u);
i++;
}
DateTime dt = DateTime.Now;
bbc = dbc.inserttable("ddd", list.ToArray());
DateTime dt2 = DateTime.Now;
listBox1.Items.Add("萬條數(shù)據(jù)插入" + (dt2-dt).TotalMilliseconds + "毫秒");
int count = 0;
dt = DateTime.Now;
var rrs = dbc.selecttable>("ddd","id<100",0,"",0,0,out count);
dt2 = DateTime.Now;
listBox1.Items.Add("數(shù)據(jù)SQL查詢" + (dt2 - dt).TotalMilliseconds + "毫秒");
dbc.Removetable("ddd");