Refer to the RedisHashService class for encapsulation in The first article

Redis data structure Hash use

using (RedisHashService service = new RedisHashService())
{
service.SetEntryInHash("student"."id"."001");
service.SetEntryInHash("student"."name"."Zhang Xiaoxu");
service.SetEntryInHash("student"."remark"."La la la la");

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"."Prince Prince");
service.SetEntryInHashIfNotExists("student"."description"."Ha ha ha.");

Console.WriteLine(service.GetValueFromHash("student"."name"));
Console.WriteLine(service.GetValueFromHash("student"."description"));
service.RemoveEntryFromHash("student"."description");
Console.WriteLine(service.GetValueFromHash("student"."description"));
Copy the code

case

service.FlushAll();
// reflection traversal
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");
// The entire storage
 service.StoreAsHash<UserInfo>(user);// Select * from 'ID'
 var result = service.GetFromHash<UserInfo>(user.Id);
}
Copy the code

Extended edition

using (RedisHashService service = new RedisHashService())
                {
                    service.KeyFulsh();
                    service.SetEntryInHash("lisi"."id"."15");

                    service.SetEntryInHash("zhangsan"."id"."13");
                    service.SetEntryInHash("zhangsan"."Name"."Thirteen");
                    service.SetEntryInHashIfNotExists("zhangsan"."Remark"."1234567");
                    var value13 = service.GetHashValues("zhangsan");
                    var key13 = service.GetHashKeys("zhangsan");

                    var dicList = service.GetAllEntriesFromHash("zhangsan");

                    service.SetEntryInHash("zhangsan"."id"."14");// Overwrite the same data
                    service.SetEntryInHash("zhangsan"."Name"."Fourteen");
                    service.SetEntryInHashIfNotExists("zhangsan"."Remark"."2345678");// The same data is not overwritten
                    service.SetEntryInHashIfNotExists("zhangsan"."Other"."234543");// Add without data
                    service.SetEntryInHashIfNotExists("zhangsan"."OtherField"."1235665");


                    var value14 = service.GetHashValues("zhangsan");
                    service.RemoveEntryFromHash("zhangsan"."Remark");
                    service.SetEntryInHashIfNotExists("zhangsan"."Remark"."2345678");
                    value14 = service.GetHashValues("zhangsan");

                    service.StoreAsHash<Student>(student_1);
                    Student student1 = service.GetFromHash<Student>(11);
                    service.StoreAsHash<Student>(student_2);
                    Student student2 = service.GetFromHash<Student>(12);
                }
Copy the code