• 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         }
  • 相关阅读:
    黑马java课程2222
    屏幕亮度软件和一些自己必用的软件设置
    ahk保存
    天天洗一次澡还真是好方法
    自动化测试 就这两张图
    python __init__.py用途
    bash检查文件格式
    cygwin中运行命令提示command not found的解决方法
    Python批量插入SQL Server数据库
    怎样去掉FireFox的导入向导
  • 原文地址:https://www.cnblogs.com/happygx/p/8416643.html
Copyright © 2020-2023  润新知