zoukankan      html  css  js  c++  java
  • C#操作Redis SortedSet 有序集合

     1 /// <summary>
     2         /// Redis 有序集合
     3         /// </summary>
     4         public static void Redis_SetSorted()
     5         {
     6             RedisClient client = new RedisClient("127.0.0.1", 6379);
     7             //清空数据库缓存,慎用
     8             client.FlushAll();
     9 
    10             /*
    11              sorted set 是set的一个升级版本,它在set的基础上增加了一个顺序的属性,这一属性在添加修改.元素的时候可以指定,
    12              * 每次指定后,zset(表示有序集合)会自动重新按新的值调整顺序。可以理解为有列的表,一列存 value,一列存顺序。操作中key理解为zset的名字.
    13              */
    14 
    15 
    16             #region  SetSorted 不设置序号
    17             //默认不设置序号  则会按照插入顺序来展示  首先插入的序号最小 往后增加
    18             client.AddItemToSortedSet("SetSorted", "1.刘仔");
    19             client.AddItemToSortedSet("SetSorted", "2.星仔");
    20             client.AddItemToSortedSet("SetSorted", "3.猪仔");
    21             List<string> listSetSorted = client.GetAllItemsFromSortedSet("SetSorted");
    22             //按序号由小到大展示
    23             foreach (string item in listSetSorted)
    24             {
    25                 Console.WriteLine("SetSorted  不设置序号{0}", item);
    26             }
    27             #endregion
    28 
    29             #region  SetSorted 设置序号
    30             //默认不设置序号  则会按照插入顺序来展示
    31             client.AddItemToSortedSet("SetSorted", "1.刘仔", 2);
    32             client.AddItemToSortedSet("SetSorted", "2.星仔", 3);
    33             client.AddItemToSortedSet("SetSorted", "3.猪仔", 1);
    34             listSetSorted = client.GetAllItemsFromSortedSet("SetSorted");
    35             //按序号由小到大展示
    36             foreach (string item in listSetSorted)
    37             {
    38                 Console.WriteLine("SetSorted  设置序号{0}", item);
    39             }
    40             #endregion
    41         }
  • 相关阅读:
    你是怎么把字符串“2016-11-16” 变为 “16/11/2016” 的?
    js-------》(小效果)实现倒计时及时间对象
    Ruby方法
    JAVASCRIPT事件详解-------原生事件基础....
    html5的小知识点小集合
    原生js实现的效果
    IDEA 实用功能Auto Import:自动优化导包(自动删除、导入包)
    8.SpringBoot 模板引擎 Thymeleaf
    7.SpringBoot 之 Web
    6.日志的使用
  • 原文地址:https://www.cnblogs.com/youmingkuang/p/14276950.html
Copyright © 2011-2022 走看看