|
|
@ -26,6 +26,7 @@ namespace RedisStudyTest
|
|
|
|
private List<Student> students;
|
|
|
|
private List<Student> students;
|
|
|
|
private Student student = null;
|
|
|
|
private Student student = null;
|
|
|
|
private string preHashKey = "RedisStudy:Student:";
|
|
|
|
private string preHashKey = "RedisStudy:Student:";
|
|
|
|
|
|
|
|
private int keyExpireSeconds = 20;
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 构造
|
|
|
|
/// 构造
|
|
|
@ -77,6 +78,10 @@ namespace RedisStudyTest
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 添加或更新学习
|
|
|
|
#region 添加或更新学习
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 参数异常测试
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void AddStudentExceptionTest()
|
|
|
|
public void AddStudentExceptionTest()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -88,6 +93,9 @@ namespace RedisStudyTest
|
|
|
|
Assert.Throws<ArgumentNullException>(() => hashStudy.HashSet(preHashKey + "-1", new HashEntry[] { }));
|
|
|
|
Assert.Throws<ArgumentNullException>(() => hashStudy.HashSet(preHashKey + "-1", new HashEntry[] { }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 参数When测试
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void AddStudentWhenTest()
|
|
|
|
public void AddStudentWhenTest()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -108,6 +116,66 @@ namespace RedisStudyTest
|
|
|
|
Assert.True(id_When_Always_NotExists);
|
|
|
|
Assert.True(id_When_Always_NotExists);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 添加一个默认学生
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void AddStudentTest()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string redisKey = preHashKey + student.Id;
|
|
|
|
|
|
|
|
var studentEntries = new HashEntry[]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new HashEntry("Id",1),
|
|
|
|
|
|
|
|
new HashEntry("Name",student.Name),
|
|
|
|
|
|
|
|
new HashEntry("Age",student.Age),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//插入Sudent
|
|
|
|
|
|
|
|
var addHash = hashStudy.HashSet(redisKey, studentEntries, CommandFlags.None);
|
|
|
|
|
|
|
|
Assert.True(addHash);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置过期
|
|
|
|
|
|
|
|
redisDatabase.KeyExpire(redisKey, TimeSpan.FromSeconds(keyExpireSeconds));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 添加一组初始化设置的学生
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void AddStudentsTest()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (var temp in students)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string redisKey = preHashKey + temp.Id;
|
|
|
|
|
|
|
|
var studentEntries = new HashEntry[]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
new HashEntry("Id", temp.Id),
|
|
|
|
|
|
|
|
new HashEntry("Name", temp.Name),
|
|
|
|
|
|
|
|
new HashEntry("Age", temp.Age),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//插入Sudent
|
|
|
|
|
|
|
|
var addStudent = hashStudy.HashSet(redisKey, studentEntries);
|
|
|
|
|
|
|
|
Assert.True(addStudent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//设置过期
|
|
|
|
|
|
|
|
redisDatabase.KeyExpire(redisKey, TimeSpan.FromSeconds(keyExpireSeconds));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 更新学生异常测试
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void UpdateStudentExceptionTest()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string redisKey = preHashKey + student.Id;
|
|
|
|
|
|
|
|
//不存在Key, 返回false,不异常
|
|
|
|
|
|
|
|
Assert.False(hashStudy.HashSet(string.Empty, "Id", -1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|