public override void DecrementCounter(string key) { using (var repository = new Repository()) { var counter = repository.Session.Query<Counter>().FirstOrDefault(t => t.Key == key); if (counter == null) { counter = new Counter { Id = Guid.NewGuid().ToString(), Key = key, Value = 0 }; } counter.Value -= 1; repository.Save(counter); } }
public override void IncrementCounter(string key, TimeSpan expireIn) { using (var repository = new Repository()) { var counter = repository.Session.Query<Counter>().FirstOrDefault(t => t.Key == key); if (counter == null) { counter = new Counter { Id = Guid.NewGuid().ToString(), ExpireAt = DateTime.UtcNow.Add(expireIn), Key = key, Value = 0 }; } counter.Value += 1; repository.Save(counter); } }
public override void DecrementCounter(string key, TimeSpan expireIn) { var id = Repository.GetId(typeof(Counter), key); if (_session.Load<Counter>(id) == null) { var counter = new Counter() { Id = id, Value = -1 }; _session.Store(counter); if (expireIn != TimeSpan.MinValue) { _session.Advanced.AddExpire(counter, DateTime.UtcNow + expireIn); } } else { _patchRequests.Add(new KeyValuePair<string, PatchRequest>(id, new PatchRequest() { Type = PatchCommandType.Inc, Name = "Value", Value = -1 })); } }