private RepositoryKey GetUserKey(string id) { RepositoryKey userKey = new RepositoryKey(this, new ObjectKey("User", id)); userKey.AddIndex(new IndexKey(this, "Index:Users:All", false)); return(userKey); }
public async Task TestIdentity() { Redis.PersistencyRegistration.RegisterHashsetSingle <Identity>(); var key1 = new RepositoryKey(Repository.Object, new ObjectKey("Test1")); key1.AddIndex(ListAll); var items = Redis.Client.GetRecords <Identity>(ListAll).ToEnumerable().ToArray(); Assert.AreEqual(0, items.Length); var identity = new Identity(); identity.Environment = "Ev"; await Redis.Client.AddRecord(key1, identity).ConfigureAwait(false); var key2 = new RepositoryKey(Repository.Object, new ObjectKey("Test2")); key2.AddIndex(ListAll); await Redis.Client.AddRecord(key2, identity).ConfigureAwait(false); items = Redis.Client.GetRecords <Identity>(ListAll).ToEnumerable().ToArray(); Assert.AreEqual(2, items.Length); Assert.AreEqual("Ev", items[0].Environment); var count = await Redis.Client.Count(ListAll).ConfigureAwait(false); Assert.AreEqual(2, count); }
private RepositoryKey GetProductKey(string id) { RepositoryKey productKey = new RepositoryKey(this, new ObjectKey("Product", id)); productKey.AddIndex(new IndexKey(this, "Index:Products:All", false)); return(productKey); }
public async Task AddUpdate() { Redis.PersistencyRegistration.RegisterHashsetSingle <Identity>(); RepositoryKey.AddIndex(new IndexKey(Repository.Object, "Data", true)); await Redis.Client.DeleteAll <Identity>(RepositoryKey).ConfigureAwait(false); await Redis.Client.AddRecord(RepositoryKey, Routing).ConfigureAwait(false); await Redis.Client.DeleteAll <Identity>(RepositoryKey).ConfigureAwait(false); await Redis.Client.AddRecord(RepositoryKey, Routing).ConfigureAwait(false); }
public void Save(AmazonReview amazon, Dictionary <string, RedisValue> review) { var value = new Dictionary <string, string>(); foreach (var redisValue in review) { value[redisValue.Key] = redisValue.Value.ToString(); } var dataKey = new RepositoryKey(this, new ObjectKey(amazon.Id)); dataKey.AddIndex(new IndexKey(this, "All", false)); manager.Client.AddRecord(dataKey, value); }
public async Task <bool> Save(LightDocument document) { if (document is null) { throw new ArgumentNullException(nameof(document)); } if (string.IsNullOrEmpty(document.Id)) { throw new ArgumentException("Value cannot be null or empty id.", nameof(document.Id)); } await local.Save(document).ConfigureAwait(false); var key = new RepositoryKey(this, new ObjectKey(document.Id)); key.AddIndex(new IndexKey(this, "Index:All", false)); key.AddIndex(new IndexKey(this, $"Index:{document.GetId()}", true)); key.AddIndex(new IndexKey(this, $"Index:{document.GetTextId()}", true)); await manager.Client.AddRecord(key, document).ConfigureAwait(false); return(true); }
public async Task Single() { Redis.PersistencyRegistration.RegisterHashsetSingle <Identity>(); Routing.ApplicationId = null; await Redis.Client.AddRecord(RepositoryKey, Routing).ConfigureAwait(false); RepositoryKey.AddIndex(new IndexKey(Repository.Object, "Data", true)); await Redis.Client.AddRecord(RepositoryKey, Routing).ConfigureAwait(false); var result = await Redis.Client.GetRecords <Identity>(RepositoryKey).ToArray(); var result2 = await Redis.Client.GetRecords <Identity>(new IndexKey(Repository.Object, "Data", true)).ToArray(); await Redis.Client.DeleteAll <Identity>(RepositoryKey).ConfigureAwait(false); Assert.AreEqual(1, result.Length); Assert.AreEqual(1, result2.Length); Assert.IsTrue(string.IsNullOrEmpty(result[0].ApplicationId)); Assert.AreEqual("DEV", result[0].Environment); }
public async Task AddToLimitedListTransaction() { var transaction = Redis.StartTransaction(); RepositoryKey.AddIndex(ListAll); var result = await Redis.Client.ContainsRecord <string>(RepositoryKey).ConfigureAwait(false); Assert.IsFalse(result); var task1 = transaction.Client.AddRecord(RepositoryKey, "Test1"); var task2 = transaction.Client.AddRecord(RepositoryKey, "Test2"); var task3 = transaction.Client.AddRecord(RepositoryKey, "Test3"); await transaction.Commit().ConfigureAwait(false); await Task.WhenAll(task1, task2, task3).ConfigureAwait(false); result = await Redis.Client.ContainsRecord <string>(RepositoryKey).ConfigureAwait(false); Assert.IsTrue(result); var value = await Redis.Client.GetRecords <string>(RepositoryKey).ToArray(); Assert.AreEqual(2, value.Length); Assert.AreEqual("Test2", value[0]); Assert.AreEqual("Test3", value[1]); }
public async Task TestIndex(int type, int batchSize) { Redis.Client.BatchSize = batchSize; SetupPersistency(type); var key1 = new RepositoryKey(Repository.Object, new ObjectKey("Test1")); key1.AddIndex(ListAll); key1.AddIndex(ListAll2); await Redis.Client.AddRecord(key1, new Identity { Environment = "Test1" }).ConfigureAwait(false); var key2 = new RepositoryKey(Repository.Object, new ObjectKey("Test2")); key2.AddIndex(ListAll); key2.AddIndex(ListAll2); await Redis.Client.AddRecord(key2, new Identity { Environment = "Test2" }).ConfigureAwait(false); var key3 = new RepositoryKey(Repository.Object, new ObjectKey("Test3")); key3.AddIndex(ListAll); await Redis.Client.AddRecord(key3, new Identity { Environment = "Test3" }).ConfigureAwait(false); var items = Redis.Client.GetRecords <Identity>(ListAll).ToEnumerable().OrderBy(item => item.Environment).ToArray(); Assert.AreEqual(3, items.Length); Assert.AreEqual("Test1", items[0].Environment); Assert.AreEqual("Test2", items[1].Environment); Assert.AreEqual("Test3", items[2].Environment); items = Redis.Client.GetRecords <Identity>(ListAll2).ToEnumerable().OrderBy(item => item.Environment).ToArray(); Assert.AreEqual(2, items.Length); Assert.AreEqual("Test1", items[0].Environment); Assert.AreEqual("Test2", items[1].Environment); items = await Redis.Client.GetRecords <Identity>(ListAll, 0, 0).ToArray(); Assert.AreEqual(1, items.Length); Assert.AreEqual("Test3", items[0].Environment); items = Redis.Client.GetRecords <Identity>(ListAll, 1, 3).ToEnumerable().OrderBy(item => item.Environment).ToArray(); Assert.AreEqual(2, items.Length); Assert.AreEqual("Test1", items[0].Environment); Assert.AreEqual("Test2", items[1].Environment); items = await Redis.Client.GetRecords <Identity>(ListAll, 3, 4).ToArray(); Assert.AreEqual(0, items.Length); var factory = new IndexManagerFactory(new NullLoggerFactory(), Redis); var manager = factory.Create(ListAll); var count = await manager.Count(Redis.Database, ListAll).ConfigureAwait(false); Assert.AreEqual(3, count); count = await Redis.Client.Count(ListAll).ConfigureAwait(false); Assert.AreEqual(3, count); count = (await manager.GetIds(Redis.Database, ListAll).ToArray()).Length; Assert.AreEqual(3, count); var result = await manager.GetIds(Redis.Database, ListAll, 1, 2).ToArray(); Assert.AreEqual("Test2", (string)result[0]); result = await manager.GetIds(Redis.Database, ListAll, 0, 1).ToArray(); Assert.AreEqual("Test3", (string)result[0]); await manager.Reset(Redis.Database, ListAll).ConfigureAwait(false); count = await manager.Count(Redis.Database, ListAll).ConfigureAwait(false); Assert.AreEqual(0, count); await Redis.Reindex(new NullLoggerFactory(), key2).ConfigureAwait(false); count = await manager.Count(Redis.Database, ListAll).ConfigureAwait(false); Assert.AreEqual(3, count); }