예제 #1
0
        public void ListRangeTrimSync()
        {
            var testModelsA = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();
            var testModelsB = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            _client.ListRightPushRange("ListRangeTrimSyncA", testModelsA);
            _client.ListRightPushRange("ListRangeTrimSyncB", testModelsB);
            _client.ListRightPopLeftPush <TestModel>("ListRangeTrimSyncA", "ListRangeTrimSyncB");

            Assert.Equal(testModelsA.Count - 1, _client.ListLength("ListRangeTrimSyncA"));
            Assert.Equal(testModelsB.Count + 1, _client.ListLength("ListRangeTrimSyncB"));

            var testModelsResultB = _client.ListRange <TestModel>("ListRangeTrimSyncB", 1, 10);

            for (var i = 0; i < testModelsA.Count; i++)
            {
                Assert.Equal(testModelsB[i], testModelsResultB[i]);
            }

            _client.ListTrim("ListRangeTrimSyncA", 0, 9);
            for (var i = 0; i < testModelsA.Count - 1; i++)
            {
                Assert.Equal(testModelsA[i], _client.ListLeftPop <TestModel>("ListRangeTrimSyncA"));
            }

            Assert.Equal(0, _client.ListLength("ListRangeTrimSyncA"));

            _client.Delete("ListRangeTrimSyncA");
            _client.Delete("ListRangeTrimSyncB");
        }
예제 #2
0
        public async void HashAsync()
        {
            var testModel = TestModelFactory.CreateTestModel();

            Assert.True(await _client.HashAddAsync("HashAsyncTest", testModel.Id.ToString(), testModel));
            var result = await _client.HashGetAsync <TestModel>("HashAsyncTest", testModel.Id.ToString());

            Assert.Equal(testModel, result);
            Assert.True(_client.HashDelete("HashAsyncTest", result.Id.ToString()));
        }
예제 #3
0
        public void HashSync()
        {
            var testModel = TestModelFactory.CreateTestModel();

            Assert.True(_client.HashAdd("HashTest", testModel.Id.ToString(), testModel));
            var result = _client.HashGet <TestModel>("HashTest", testModel.Id.ToString());

            Assert.Equal(testModel, result);
            Assert.True(_client.HashDelete("HashTest", result.Id.ToString()));
        }
        public async void StringAsync()
        {
            var testModel = TestModelFactory.CreateTestModel();

            Assert.True(await _client.AddAsync(testModel.Id.ToString(), testModel));
            var result = await _client.GetAsync <TestModel>(testModel.Id.ToString());

            Assert.Equal(testModel, result);
            Assert.True(await _client.DeleteAsync(result.Id.ToString()));
        }
        public void StringBatchSync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            _client.AddRange(testModels.ToDictionary(k => k.Id.ToString(), v => v));
            var results = _client.Get <TestModel>(testModels.Select(model => model.Id.ToString()).ToList());

            Assert.True(results.All(result => testModels.Any(model => model.Equals(result))));
            Assert.Equal(results.Count, _client.DeleteAll(results.Select(result => result.Id.ToString()).ToList()));
        }
        public void StringSync()
        {
            var testModel = TestModelFactory.CreateTestModel();

            Assert.True(_client.Add(testModel.Id.ToString(), testModel));
            var result = _client.Get <TestModel>(testModel.Id.ToString());

            Assert.Equal(testModel, result);
            Assert.True(_client.Delete(result.Id.ToString()));
        }
예제 #7
0
        public async void HashAllAsync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            _client.HashAddRangeAsync("HashAllAsyncTest", testModels.ToDictionary(k => k.Id.ToString(), v => v)).Wait();
            var results = await _client.HashGetAsync <TestModel>("HashAllAsyncTest");

            Assert.True(results.All(result => testModels.Any(model => model.Equals(result))));
            var keys = await _client.HashGetAllEntityKeysAsync("HashAllAsyncTest");

            Assert.True(keys.All(key => testModels.Any(model => model.Id.ToString() == key)));
            Assert.Equal(results.Count, await _client.HashCountAsync("HashAllAsyncTest"));
            Assert.True(await _client.DeleteAsync("HashAllAsyncTest"));
        }
예제 #8
0
        public async void HashBatchAsync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            _client.HashAddRangeAsync("HashBatchAsyncTest", testModels.ToDictionary(k => k.Id.ToString(), v => v))
            .Wait();
            var results = await _client.HashGetRangeAsync <TestModel>("HashBatchAsyncTest",
                                                                      testModels.Select(model => model.Id.ToString()).ToList());

            Assert.True(results.All(result => testModels.Any(model => model.Equals(result))));
            Assert.Equal(results.Count,
                         await _client.HashDeleteRangeAsync("HashBatchAsyncTest",
                                                            results.Select(testModel => testModel.Id.ToString()).ToList()));
        }
예제 #9
0
        public void ListPushPopSync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            _client.ListLeftPushRange("ListPushPopSync", testModels);
            testModels.ForEach(testModel =>
                               Assert.Equal(testModel, _client.ListRightPop <TestModel>("ListPushPopSync")));

            _client.ListRightPushRange("ListPushPopSync", testModels);
            testModels.ForEach(testModel =>
                               Assert.Equal(testModel, _client.ListLeftPop <TestModel>("ListPushPopSync")));

            _client.Delete("ListPushPopSync");
        }
예제 #10
0
        public void ListInsertSync()
        {
            var testModel       = TestModelFactory.CreateTestModel();
            var testBeforeModel = TestModelFactory.CreateTestModel();
            var testAfterModel  = TestModelFactory.CreateTestModel();

            _client.ListRightPush("ListInsertSync", testModel);
            _client.ListInsertBefore("ListInsertSync", testModel, testBeforeModel);
            _client.ListInsertAfter("ListInsertSync", testModel, testAfterModel);

            Assert.Equal(testBeforeModel, _client.ListLeftPop <TestModel>("ListInsertSync"));
            Assert.Equal(testAfterModel, _client.ListRightPop <TestModel>("ListInsertSync"));
            Assert.Equal(1, _client.ListRemove("ListInsertSync", testModel));

            _client.Delete("ListInsertSync");
        }
예제 #11
0
        public void ListOprByIndexSync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            for (var i = 0; i < 10; i++)
            {
                _client.ListLeftPush("ListOprByIndexSync", (TestModel)null);
            }
            for (var i = 0; i < testModels.Count; i++)
            {
                _client.ListSetByIndex("ListOprByIndexSync", i, testModels[i]);
            }
            for (var i = 0; i < testModels.Count; i++)
            {
                Assert.Equal(testModels[i], _client.ListGetByIndex <TestModel>("ListOprByIndexSync", i));
            }
            _client.Delete("ListOprByIndexSync");
        }
예제 #12
0
        public void ListSync()
        {
            var testModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            Assert.Equal(testModels.Count, _client.ListLeftPushRange("ListSync", testModels));
            Assert.Equal(testModels.Count, _client.ListLength("ListSync"));
            for (var i = 0; i < testModels.Count; i++)
            {
                Assert.Equal(testModels[i],
                             _client.ListGetByIndex <TestModel>("ListSync", testModels.Count - 1 - i));
            }

            var testLeftModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            Assert.Equal(testLeftModels.Count + testModels.Count, _client.ListLeftPushRange("ListSync", testLeftModels));
            Assert.Equal(testLeftModels.Count + testModels.Count, _client.ListLength("ListSync"));
            for (var i = 0; i < testLeftModels.Count; i++)
            {
                Assert.Equal(testLeftModels[i],
                             _client.ListGetByIndex <TestModel>("ListSync", testLeftModels.Count - 1 - i));
            }

            var testRightModels = Enumerable.Range(0, 10).Select(p => TestModelFactory.CreateTestModel()).ToList();

            Assert.Equal(testLeftModels.Count + testModels.Count + testRightModels.Count,
                         _client.ListRightPushRange("ListSync", testRightModels));
            Assert.Equal(testLeftModels.Count + testModels.Count + testRightModels.Count,
                         _client.ListLength("ListSync"));
            for (var i = 0; i < testRightModels.Count; i++)
            {
                Assert.Equal(testRightModels[i],
                             _client.ListGetByIndex <TestModel>("ListSync",
                                                                testLeftModels.Count + testModels.Count + i));
            }

            _client.Delete("ListSync");
        }