RedisHashService 类请参考第一篇的封装
redis 数据结构Hash的使用
using (RedisHashService service = new RedisHashService())
{
service.SetEntryInHash("student", "id", "001");
service.SetEntryInHash("student", "name", "张小徐");
service.SetEntryInHash("student", "remark", "啦啦啦");
var keys = service.GetHashKeys("student");
var values = service.GetHashValues("student");
var keyValues = service.GetAllEntriesFromHash("student");
Console.WriteLine(service.GetValueFromHash("student", "id"));
service.SetEntryInHashIfNotExists("student", "name", "太子爷");
service.SetEntryInHashIfNotExists("student", "description", "哈哈哈");
Console.WriteLine(service.GetValueFromHash("student", "name"));
Console.WriteLine(service.GetValueFromHash("student", "description"));
service.RemoveEntryFromHash("student", "description");
Console.WriteLine(service.GetValueFromHash("student", "description"));
案例
service.FlushAll();
//反射遍历做一下
service.SetEntryInHash($"userinfo_{user.Id}", "Account", user.Account);
service.SetEntryInHash($"userinfo_{user.Id}", "Name", user.Name);
service.SetEntryInHash($"userinfo_{user.Id}", "Address", user.Address);
service.SetEntryInHash($"userinfo_{user.Id}", "Email", user.Email);
service.SetEntryInHash($"userinfo_{user.Id}", "Password", user.Password);
service.SetEntryInHash($"userinfo_{user.Id}", "Account", "Admin");
//整个存储
service.StoreAsHash<UserInfo>(user);//含ID才可以的
var result = service.GetFromHash<UserInfo>(user.Id);
}