C# Redis Server分布式缓存编程(二)

来源:互联网 发布:java方法重写规则 编辑:程序博客网 时间:2024/06/05 18:15
namespace Zeus.Cache.Redis.Demo{    public class Person    {        public int Id { get; set; }        public string Name { get; set; }        public string Surname { get; set; }        public int Age { get; set; }        public string Profession { get; set; }    }}
复制代码
复制代码
namespace Zeus.Cache.Redis.Demo{    public class Phone    {        public int Id { get; set; }        public string Model { get; set; }        public string Manufacturer { get; set; }        public Person Owner { get; set; }    }}
复制代码
复制代码
public void EntityDemo()        {            using (RedisClient redisClient = new RedisClient(host))            {                IRedisTypedClient<Phone> phones = redisClient.As<Phone>();                Phone phoneFive = phones.GetValue("5");                if (phoneFive == null)                {                    // make a small delay                    Thread.Sleep(2000);                    // creating a new Phone entry                    phoneFive = new Phone                    {                        Id = 5,                        Manufacturer = "Nokia",                        Model = "Lumia 200",                        Owner = new Person                        {                            Id = 1,                            Age = 90,                            Name = "OldOne",                            Profession = "sportsmen",                            Surname = "OldManSurname"                        }                    };                    // adding Entry to the typed entity set                    phones.SetEntry(phoneFive.Id.ToString(), phoneFive);                }                string message = "Phone model is " + phoneFive.Manufacturer;                message += "\nPhone Owner Name is: " + phoneFive.Owner.Name;                Console.WriteLine(message);            }        }
复制代码

运行结果:

0 0
原创粉丝点击