Exemplo n.º 1
0
        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
        }
Exemplo n.º 2
0
 public FastObject Get(string key)
 {
     database = Fastdb.Instance();
        var value= database.keys[key];
     value.refcount++;
     value.lasttime = database.systime;
     return value;
 }
Exemplo n.º 3
0
 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 });
 }
Exemplo n.º 4
0
 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 });
 }
Exemplo n.º 5
0
 public void Load(string key, FastObject entity)
 {
     database = Fastdb.Instance();
     database.keys.Add(key, entity);
 }
Exemplo n.º 6
0
 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 });
 }
Exemplo n.º 7
0
 public bool EnSure(string key)
 {
     database = Fastdb.Instance();
     return database.keys.ContainsKey(key);
 }
Exemplo n.º 8
0
        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;
        }
Exemplo n.º 9
0
        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;
                }
            }
        }