zoukankan      html  css  js  c++  java
  • C# Redis Server分布式缓存编程(二)

    在Redis编程中, 实体和集合类型则更加有趣和实用

    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 += "
    Phone Owner Name is: " + phoneFive.Owner.Name;
    
                    Console.WriteLine(message);
                }
            }

    运行结果:

  • 相关阅读:
    print 参数
    note
    action标签的属性说明
    Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
    润乾报表
    javax.naming.NameNotFoundException: Name ZKING is not bound in this Context 的问题
    Myeclipse2013安装svn插件
    Myeclipse2013的优化设置
    Myeclipse解析.classpath文件
    Struts
  • 原文地址:https://www.cnblogs.com/davidgu/p/3263485.html
Copyright © 2011-2022 走看看