zoukankan      html  css  js  c++  java
  • C#操作Redis String字符串(1)

     1 /// <summary>
     2        /// Redis String 操作
     3        /// </summary>
     4        public static void Redis_String()
     5        {
     6            RedisClient client = new RedisClient("127.0.0.1", 6379);
     7            //清空数据库缓存,慎用
     8            client.FlushAll();
     9            /*
    10                 * 注意这个exp的时间,之前以为是以毫秒计算,所以设置一天过期的话只写了86400000,
    11                 * 然而,他这里的最小单位似乎是。。100ns。。也就是1个ticks=100毫微秒=100纳秒。
    12                 * 所以应该写成864000000000表示一天。
    13                 * TimeSpan exp = new TimeSpan(864000000000);
    14                 * 1秒=10000000ns
    15                 */
    16            #region string
    17  
    18            long second = 864000000000;
    19            TimeSpan exp = new TimeSpan((long)second);
    20            //设置有效期
    21            client.Add<string>("StringValueTime", "设置时间为一天有效期", exp);
    22  
    23            //不设置有效期
    24            client.Add<string>("StringValue", "我是永久的");
    25            Console.WriteLine("取值{0}", client.Get<string>("StringValue"));
    26  
    27            //由于redis不支持对象,C#DLL底层实现是,将当前对象传递进去后,自动序列化为json字符串进行存储
    28            // 获取后反序列化
    29            Student stud = new Student() { id = "1001", name = "李四" };
    30            client.Add<Student>("StringEntity", stud);
    31  
    32            Student Get_stud = client.Get<Student>("StringEntity");
    33            Console.WriteLine("数据类型为:String.键:StringEntity,值:{0} {1}", Get_stud.id, Get_stud.name);
    34            #endregion
    35        }

    https://www.cnblogs.com/happygx/p/8416598.html

  • 相关阅读:
    第01组 每周小结(2/3)(组长)
    第01组 每周小结 (1/3)(组长)
    第01组 Beta冲刺 总结(组长)
    第01组Beta冲刺(5/5)(组长)
    第01组Beta冲刺(4/5)(组长)
    第01组Beta冲刺(3/5)(组长)
    第01组Beta冲刺(2/5)(组长)
    第01组Beta冲刺(1/5)(组长)
    软工实践个人总结
    每周小结(3/3)
  • 原文地址:https://www.cnblogs.com/youmingkuang/p/14276909.html
Copyright © 2011-2022 走看看