public void HashExpireInAsyncTest() { var test_key = "test_hash_expire_in"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); _RedisService.HashExpireInAsync(test_key, new TimeSpan(0, 0, 5)); Task.Factory.StartNew(() => { Task.Delay(6).Wait(); hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(0, hashCount); _RedisService.HashRemoveAllAsync(test_key).Wait(); }); }
public void HashRemoveAsyncTest() { var test_key = "test_hash_remove"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var delResult = _RedisService.HashRemoveAsync(test_key, 1).Result; Assert.True(delResult); hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(9, hashCount); var hashValue = _RedisService.HashGetAsync <string>(test_key, 1).Result; Assert.Null(hashValue); _RedisService.HashRemoveAllAsync(test_key); }
public void HashGetAllAsyncTest() { var test_key = "test_hash_get_all"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var hashValues = _RedisService.HashGetAllAsync <string>(test_key).Result.ToList(); Assert.Equal(10, hashValues.Count()); Assert.Contains("第1条测试数据", hashValues); Assert.Contains("第4条测试数据", hashValues); Assert.Contains("第7条测试数据", hashValues); Assert.DoesNotContain("第11条测试数据", hashValues); _RedisService.HashRemoveAllAsync(test_key).Wait(); }
public void HashGetAllAsyncBackWithHashEntryArrayTest() { var test_key = "test_hash_get_all"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var hashEntries = _RedisService.HashGetAllAsync(test_key).Result.ToList(); Assert.Equal(10, hashEntries.Count()); var firstValue = hashEntries.First(); Assert.Equal("0", firstValue.Name); Assert.Equal("第0条测试数据", JsonManager.Deserialize <string>(firstValue.Value)); _RedisService.HashRemoveAllAsync(test_key).Wait(); }
public async Task HashCountAsyncTest() { var test_key = "test_hash_remove_count"; await _RedisService.HashRemoveAllAsync(test_key); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); await _RedisService.HashRemoveAsync(test_key, 1); hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(9, hashCount); await _RedisService.HashRemoveAsync(test_key, new List <RedisValue>() { 2, 3 }); hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(7, hashCount); await _RedisService.HashRemoveAllAsync(test_key); }
public async Task HashGetAsyncTest() { var test_key = "test_hash_get_by_field"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var hashValue = _RedisService.HashGetAsync <string>(test_key, 1).Result; Assert.Equal("第1条测试数据", hashValue); hashValue = _RedisService.HashGetAsync <string>(test_key, 8).Result; Assert.Equal("第8条测试数据", hashValue); await _RedisService.HashRemoveAllAsync(test_key); }
public void HashExistsAsyncTest() { var test_key = "test_hash_remove_exist"; _RedisService.HashRemoveAllAsync(test_key).Wait(); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var existResult = _RedisService.HashExistsAsync(test_key, 1).Result; Assert.True(existResult); _RedisService.HashRemoveAsync(test_key, 1).Wait(); existResult = _RedisService.HashExistsAsync(test_key, 1).Result; Assert.False(existResult); _RedisService.HashRemoveAllAsync(test_key).Wait(); }
public async Task HashRemoveAsyncRangeByFileldListTest() { var test_key = "test_hash_remove_rang_by_fileld_list"; await _RedisService.HashRemoveAllAsync(test_key); var values = new List <HashEntry>(); for (int i = 0; i < 10; i++) { var hashEntry = new HashEntry(i, JsonManager.Serialize($"第{i}条测试数据")); values.Add(hashEntry); } _RedisService.HashSetRangeAsync(test_key, values).Wait(); var hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(10, hashCount); var delFilelds = new List <RedisValue>() { 1, 2, 3 }; var delResult = _RedisService.HashRemoveAsync(test_key, delFilelds).Result; Assert.Equal(3, delResult); hashCount = _RedisService.HashCountAsync(test_key).Result; Assert.Equal(7, hashCount); var hashValue = _RedisService.HashGetAsync <string>(test_key, 1).Result; Assert.Null(hashValue); hashValue = _RedisService.HashGetAsync <string>(test_key, 2).Result; Assert.Null(hashValue); hashValue = _RedisService.HashGetAsync <string>(test_key, 3).Result; Assert.Null(hashValue); await _RedisService.HashRemoveAllAsync(test_key); }
public void Serialize_Int_Test() { var result = JsonManager.Serialize(1); Assert.Equal("1", result); }
public void Serialize_Obj_NotNull_Test() { var result = JsonManager.Serialize <Test>(new Test()); Assert.NotEmpty(result); }
public void Serialize_Obj_Null_Test() { var result = JsonManager.Serialize <Test>(null); Assert.Empty(result); }