public override void SetRangeInHash(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs) { key.ThrowIfNull("key"); keyValuePairs.ThrowIfNull("keyValuePairs"); using (var repository = _storage.Repository.OpenSession()) { var id = _storage.Repository.GetId(typeof(RavenHash), key); var result = repository.Load <RavenHash>(id); if (result == null) { result = new RavenHash() { Id = id }; repository.Store(result); } foreach (var keyValuePair in keyValuePairs) { result.Fields[keyValuePair.Key] = keyValuePair.Value; } repository.SaveChanges(); } }
public void PersistHash_ClearsTheHashExpirationData() { UseConnection(repository => { var hash1 = new RavenHash { Id = repository.GetId(typeof(RavenHash), "Hash1"), Fields = new Dictionary <string, string> { { "field1", "value1" } } }; var hash2 = new RavenHash { Id = repository.GetId(typeof(RavenHash), "Hash2"), Fields = new Dictionary <string, string> { { "field2", "value2" } } }; using (var session = repository.OpenSession()) { session.Store(hash1); session.Advanced.AddExpire(hash1, DateTime.UtcNow); session.Store(hash2); session.Advanced.AddExpire(hash2, DateTime.UtcNow); session.SaveChanges(); } Commit(repository, x => x.PersistHash("Hash1")); using (var session = repository.OpenSession()) { var testHash1 = GetTestHash(session, hash1.Id); var expireAt = session.Advanced.GetExpire(testHash1); Assert.Null(expireAt); var testHash2 = GetTestHash(session, hash2.Id); expireAt = session.Advanced.GetExpire(testHash2); Assert.NotNull(expireAt); } }); }
public void ExpireHash_SetsHashExpirationData() { UseConnection(repository => { var hash1 = new RavenHash { Id = repository.GetId(typeof(RavenHash), "Hash1"), Fields = new Dictionary <string, string> { { "field1", "value1" } } }; var hash2 = new RavenHash { Id = repository.GetId(typeof(RavenHash), "Hash2"), Fields = new Dictionary <string, string> { { "field2", "value2" } } }; using (var session = repository.OpenSession()) { session.Store(hash1); session.Store(hash2); session.SaveChanges(); } Commit(repository, x => x.ExpireHash("Hash1", TimeSpan.FromDays(1))); using (var session = repository.OpenSession()) { var testHash1 = GetTestHash(session, hash1.Id); var expireAt = session.Advanced.GetExpire(testHash1); Assert.True(DateTime.UtcNow.AddMinutes(-1) < expireAt && expireAt <= DateTime.UtcNow.AddDays(1)); var testHash2 = GetTestHash(session, hash2.Id); expireAt = session.Advanced.GetExpire(testHash2); Assert.Null(expireAt); } }); }
public override void SetRangeInHash(string key, IEnumerable <KeyValuePair <string, string> > keyValuePairs) { key.ThrowIfNull("key"); keyValuePairs.ThrowIfNull("keyValuePairs"); var id = _storage.Repository.GetId(typeof(RavenHash), key); var result = _session.Load <RavenHash>(id); // Not exists? Insert if (result == null) { result = new RavenHash() { Id = id }; _session.Store(result); } foreach (var keyValuePair in keyValuePairs) { result.Fields[keyValuePair.Key] = keyValuePair.Value; } }