示例#1
0
 public void Set(string key, DBValue value)
 {
     _data.AddOrUpdate(key, value, (currentKey, existingVal) =>
     {
         return(ChooseActualValue(value, existingVal));
     });
 }
示例#2
0
        public void Remove(string key, DBValue value)
        {
            // make sure deleted value is valid
            value.IsDeleted = true;
            value.Value     = null;

            Set(key, value);
        }
示例#3
0
 private DBValue ChooseActualValue(DBValue val1, DBValue val2)
 {
     if (val1.Version > val2.Version)
     {
         return(val1);
     }
     else if (val1.Version == val2.Version && val1.ServerId < val2.ServerId)
     {
         return(val1);
     }
     else
     {
         return(val2);
     }
 }
示例#4
0
        private void ProceedWriteCommand(DBUpdateMessage message)
        {
            var dbValue = new DBValue
            {
                Value    = message.Value,
                Version  = message.Version,
                ServerId = message.ServerId
            };

            if (message.Command == "set")
            {
                _db.Set(message.Key, dbValue);
            }
            else if (message.Command == "remove")
            {
                _db.Remove(message.Key, dbValue);
            }
            else
            {
                Console.WriteLine("Unknown command");
            }
        }