HashStringStudy Test

master
ruyu 7 years ago
parent 8ae8e924ad
commit 9e152409ec

@ -30,7 +30,7 @@ namespace RedisStudyTest
private Student defaultStudent = null;
private string preStudentHashKey = "RedisStudy:Student:";
private string defaultStudentHashKey = "";
private int keyDefaultExpireSeconds = 20;
private int defaultExpireSeconds = 20;
/// <summary>
/// 构造
@ -159,7 +159,7 @@ namespace RedisStudyTest
Assert.True(addHash);
//设置过期
redisDatabase.KeyExpire(defaultStudentHashKey, TimeSpan.FromSeconds(keyDefaultExpireSeconds));
redisDatabase.KeyExpire(defaultStudentHashKey, TimeSpan.FromSeconds(defaultExpireSeconds));
}
/// <summary>
@ -184,7 +184,7 @@ namespace RedisStudyTest
Assert.True(addStudent);
//设置过期
redisDatabase.KeyExpire(redisKey, TimeSpan.FromSeconds(keyDefaultExpireSeconds));
redisDatabase.KeyExpire(redisKey, TimeSpan.FromSeconds(defaultExpireSeconds));
}
//清理删除
@ -498,7 +498,7 @@ namespace RedisStudyTest
{
AddDefaultStudent();
RedisValue[] hashFields = new RedisValue[]
RedisValue[] hashFields = new RedisValue[]
{
"Id",
"Name",
@ -631,9 +631,9 @@ namespace RedisStudyTest
{
//插入多列hash
List<HashEntry> hashEntries = new List<HashEntry>();
for (int i=1;i<=100; i++)
for (int i = 1; i <= 100; i++)
{
hashEntries.Add(new HashEntry("Field"+i,i));
hashEntries.Add(new HashEntry("Field" + i, i));
}
redisHashStudy.HashSet(defaultStudentHashKey, hashEntries.ToArray());
@ -708,7 +708,7 @@ namespace RedisStudyTest
[Fact]
public void HashDeleteNotFieldTest()
{
redisHashStudy.HashIncrement(defaultStudentHashKey, "Id",1);
redisHashStudy.HashIncrement(defaultStudentHashKey, "Id", 1);
var hashDeleteResult = redisHashStudy.HashDelete(defaultStudentHashKey, "Name");
Assert.False(hashDeleteResult);
@ -740,14 +740,14 @@ namespace RedisStudyTest
{
AddDefaultStudent();
RedisValue[] delValues = new RedisValue[]
RedisValue[] delValues = new RedisValue[]
{
"Id",
"Name",
"Age",
};
var hashDeleteResult = redisHashStudy.HashDelete(defaultStudentHashKey, delValues, CommandFlags.None);
Assert.Equal(3,hashDeleteResult);
Assert.Equal(3, hashDeleteResult);
}
#endregion

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using StackExchange.Redis;
using Xunit;
using Xunit.Extensions;
using Xunit.Serialization;
using Xunit.Abstractions;
using Xunit.Sdk;
using RedisStudyModel;
using RedisStuy;
namespace RedisStudyTest
{
[Trait("RedisString", "All")]
public class RedisStringStudyTest : IDisposable
{
#region 初始化
private readonly ITestOutputHelper testOutput;
private IDatabase redisDatabase = null;
private RedisStringStudy redisStringStudy = null;
private TimeSpan defaultExpiry =TimeSpan.FromSeconds(20);
private string defaultRedisKey = "RedisStudy:String:xUnitTest";
/// <summary>
/// 构造
/// </summary>
public RedisStringStudyTest(ITestOutputHelper output)
{
this.testOutput = output;
redisDatabase = RedisHelper.GetRedisDatabase();
redisStringStudy = new RedisStringStudy();
}
#endregion
#region StringSet
[Fact]
public void StringSet()
{
var setResult = redisStringStudy.StringSet(defaultRedisKey, "xUnit", defaultExpiry);
Assert.True(setResult);
}
#endregion
#region 清理
public void Dispose()
{
redisDatabase.KeyDelete(defaultRedisKey);
}
#endregion
}
}

@ -76,6 +76,7 @@
<ItemGroup>
<Compile Include="RedisHashStudyTest.cs" />
<Compile Include="RedisLockStudyTest.cs" />
<Compile Include="RedisStringStudyTest.cs" />
<Compile Include="RedisStudyTest.cs" />
<Compile Include="RedisSortSetStudyTest.cs" />
<Compile Include="RedisHelperTest.cs" />

Loading…
Cancel
Save