public void init(Fastdb sdb) { //var dbkv = _keyValue.Query("select top " + sdb.max + " * from KeyValueSTs order by newid()", new SqlParameter[] { }).ToList(); var dbkv = _keyValue.Query("select * from KeyValueSTs", new SqlParameter[] { }).ToList(); foreach (var item in dbkv) { switch (item.type) { case 0: sdb.keys.Add(item.key, new StringObject(item.value, FastDB.Core.ObjectType.fast_string, true, false, sdb.systime)); break; case 1: sdb.keys.Add(item.key, new FastDB.Struct.ListObject(item.value, FastDB.Core.ObjectType.fast_list, true, false, sdb.systime)); break; case 2: sdb.keys.Add(item.key, new FastDB.Struct.HashObject(item.value ,FastDB.Core.ObjectType.fast_hash, true, false, sdb.systime)); break; default: break; } } ///TODO /// sdb.auths /// sdb.users }
public FastObject Get(string key) { database = Fastdb.Instance(); var value= database.keys[key]; value.refcount++; value.lasttime = database.systime; return value; }
public void Update(string key, FastObject entity) { database = Fastdb.Instance(); if( database.keys.ContainsKey(key)) { database.keys[key] = entity; } database.dirty.Enqueue(new changelog { operaType = OperationType.Update, Key = key, Value = entity }); }
public void Delete(string key) { database = Fastdb.Instance(); if (database.keys.ContainsKey(key)) { database.keys.Remove(key); } database.dirty.Enqueue(new changelog { operaType = OperationType.Delete, Key = key, Value = null }); }
public void Load(string key, FastObject entity) { database = Fastdb.Instance(); database.keys.Add(key, entity); }
public void Insert(string key, FastObject entity) { database = Fastdb.Instance(); database.keys.Add(key, entity); database.dirty.Enqueue(new changelog { operaType=OperationType.Insert,Key= key,Value= entity }); }
public bool EnSure(string key) { database = Fastdb.Instance(); return database.keys.ContainsKey(key); }
public void sync(Fastdb sdb) { //阻塞操作 sdb.isrunning = true; //同步未存储键 while (sdb.dirty.Count != 0) { var item = sdb.dirty.Dequeue(); switch (item.operaType) { case OperationType.Insert: Insert(item.Key, item.Value); break; case OperationType.Update: Update(item.Key, item.Value); break; case OperationType.Delete: Delete(item.Key); break; case OperationType.None: break; default: break; } } //剔除冷键 //if (sdb.keys.Count > sdb.max) //{ // sdb.keys = sdb.keys.OrderByDescending(p => p.Value.refcount).Take(sdb.max).ToDictionary(o => o.Key, o => o.Value); //} //同步时间 sdb.lastsync = sdb.systime; sdb.isrunning = false; }
public void stop(Fastdb sdb) { while (sdb.isrunning) { } sdb.isrunning = true; while (sdb.dirty.Count != 0) { var item = sdb.dirty.Dequeue(); switch (item.operaType) { case OperationType.Insert: Insert(item.Key, item.Value); break; case OperationType.Update: Update(item.Key, item.Value); break; case OperationType.Delete: Delete(item.Key); break; case OperationType.None: break; default: break; } } }