public void Set(string key, DBValue value) { _data.AddOrUpdate(key, value, (currentKey, existingVal) => { return(ChooseActualValue(value, existingVal)); }); }
public void Remove(string key, DBValue value) { // make sure deleted value is valid value.IsDeleted = true; value.Value = null; Set(key, value); }
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); } }
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"); } }