/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="keyValuePairs"></param> /// <exception cref="ArgumentNullException"></exception> public override void SetRangeInHash(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs) { if (key == null) { throw new ArgumentNullException(nameof(key)); } if (keyValuePairs == null) { throw new ArgumentNullException(nameof(keyValuePairs)); } foreach (var keyValuePair in keyValuePairs) { var field = keyValuePair.Key; var value = keyValuePair.Value; QueueCommand(x => { var state = new LiteHash { Key = key, Field = field, Value = value, ExpireAt = null }; var oldHash = x.StateDataHash.Find(_ => _.Key == key && _.Field == field).FirstOrDefault(); if (oldHash == null) { x.StateDataHash.Insert(state); } else { state.Id = oldHash.Id; x.StateDataHash.Update(state); } }); } }
public void PersistHash_ClearsTheHashExpirationData() { UseConnection(database => { var hash1 = new LiteHash { Key = "Hash1", Value = "value1", ExpireAt = DateTime.Now }; database.StateDataHash.Insert(hash1); var hash2 = new LiteHash { Key = "Hash2", Value = "value2", ExpireAt = DateTime.Now }; database.StateDataHash.Insert(hash2); Commit(database, x => x.PersistHash(hash1.Key)); var testHash1 = GetTestHash(database, hash1.Key); Assert.Null(testHash1.ExpireAt); var testHash2 = GetTestHash(database, hash2.Key); Assert.NotNull(testHash2.ExpireAt); }); }
public void ExpireHash_SetsHashExpirationData() { UseConnection(database => { var hash1 = new LiteHash { Key = "Hash1", Value = "value1" }; database.StateDataHash.Insert(hash1); var hash2 = new LiteHash { Key = "Hash2", Value = "value2" }; database.StateDataHash.Insert(hash2); Commit(database, x => x.ExpireHash(hash1.Key, TimeSpan.FromDays(1))); var testHash1 = GetTestHash(database, hash1.Key); Assert.True(DateTime.UtcNow.AddMinutes(-1) < testHash1.ExpireAt && testHash1.ExpireAt <= DateTime.UtcNow.AddDays(1)); var testHash2 = GetTestHash(database, hash2.Key); Assert.Null(testHash2.ExpireAt); }); }