コード例 #1
0
        public void HashTest()
        {
            // Hash操作
            Student stu1 = new Student {
                Id = 1, Name = "shz", Birthday = DateTime.Now
            };
            Student stu2 = new Student {
                Id = 2, Name = "tom", Birthday = DateTime.Now.AddDays(-10)
            };

            redisHelper.HashSet <Student>("cookie", stu1.Id.ToString(), stu1);
            redisHelper.HashSet <Student>("cookie", stu2.Id.ToString(), stu2);
            stu1 = redisHelper.HashGet <Student>("cookie", "1");
            stu2 = redisHelper.HashGet <Student>("cookie", "2");
            Console.WriteLine($"name:{stu1.Name}");
            Console.WriteLine($"name:{stu2.Name}");

            stu2.Name     = "tom2";
            stu2.Birthday = DateTime.Now.AddYears(-10);
            redisHelper.HashSet <Student>("cookie", stu2.Id.ToString(), stu2);
            List <string> keys = redisHelper.HashKeys <string>("cookie");

            keys.ForEach(s => { Console.WriteLine($"key:{s}"); });
            List <Student> stus = redisHelper.HashValues <Student>("cookie");

            stus.ForEach(s => { Console.WriteLine($"name:{s.Name},id:{s.Id}"); });
        }