Basic Tutorials of Redis(5) - Sorted Set

前端之家收集整理的这篇文章主要介绍了Basic Tutorials of Redis(5) - Sorted Set前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  The last post is mainly about the unsorted set,in this post I will show you the sorted set playing an important

role in Redis.There are many command added after the version 2.8.9.OK,let's see the below picture firstly.There

are 24 commands to handle the sorted set,the same as the string.

  

  Many commands are similar with the Set.Both of them are the set,the sorted set's 403_182@

playing a important role on sorting.We can use the zadd to store the sorted set.The following example demonstrates

the usage of zadd.

zadd - - b c d e f g h i j k

  For learning how many elements in the set,and who are them ? we can use the command zrange.
zrange - -

  zrange can also make us know the @R_403_182@s of the elements,we should open seletion the with@R_403_182@s to 

find out their @R_403_182@s.

zrange - - with@R_403_182@s

  There are another intresting commands to get the members.zrangeby@R_403_182@ can find out the members by

their @R_403_182@s.For an instance,I want to find out the members' @R_403_182@s between 0 and 6,so I will use  403_182@ -  

zrangebylex can find out the members by the lexicographical order when some of them are in

the same @R_403_182@s.Now I want to find out the members that order by lexicography when the @R_403_182@ are the same

while in the range (a,k],so using  - (a [k  can easily do this job.

zrank.For descending

we use zrevrank .For example,we want to know the member d's rank.

zrank -- d

   There are also many command that we can use to remove the member from the set.Using zrem to remove one or

more members,Using zremrangebyrank to remove the members by their ranks.Using the zremrangeby@R_403_182@ to remove

the members by their @R_403_182@s.Using the zremrangebylex to remove the members by their rank and lexicography.

zrem -- b c

zremrangebyrank -

zremrangeby@R_403_182@ -

zremrangebylex - (e (j

403_182@,we can use z@R_403_182@ to get its @R_403_182@.To get the @R_403_182@ of member e,

we use  403_182@ - e .For learning how many members in the set by the range of @R_403_182@,we can use zcount

to get the amount.To get the amount of the set by the @R_403_182@'s range [0,10],we can use  -  .

   Can we modify the @R_403_182@s of the members?Of course we can.Not only the exists member but also the

member not in the set.If the member not exists in the set,Redis will store a new member to the set.For

example,I want to modify the @R_403_182@ of d which is not exists in the set.I will use  - d  to finish

this easy job.And the result is that the set will has a new member with @R_403_182@ 1.

  OK,thoes commands are what I want to show you for sorted set.Let's go on to see how StackExchange.Redis

Handle the sorted set.

db.SortedSetAdd(,, set_1 = SortedSetEntry[ SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, SortedSetEntry(, db.SortedSetAdd( Console.WriteLine(403_182@ ascending ( item db.SortedSetRangeByRank(,,- Console.Write(item + Console.WriteLine( ( item db.SortedSetRangeByRankWith@R_403_182@s( Console.WriteLine(.Format(403_182@ {1}403_182@)); 403_182@ Console.WriteLine(403_182@ ( item db.SortedSetRangeBy@R_403_182@(, Console.Write(item + Console.WriteLine( Console.WriteLine( ( item db.SortedSetRangeByValue(, Console.Write(item + Console.WriteLine( Console.WriteLine(.Format(,db.SortedSetRank(, Console.WriteLine(.Format(,Order.Descending))); db.SortedSetRemove(, db.SortedSetRemove(, RedisValue[] { , Console.WriteLine( ( item db.SortedSetRangeByRank(,Order.Ascending)) Console.Write(item + db.SortedSetRemoveRangeByRank(, Console.WriteLine( ( item db.SortedSetRangeByRank(,Order.Ascending)) Console.Write(item + 403_182@ db.SortedSetRemoveRangeBy@R_403_182@(, Console.WriteLine(403_182@: ( item db.SortedSetRangeByRank(,Order.Ascending)) Console.Write(item + db.SortedSetRemoveRangeByValue(,, Console.WriteLine( ( item db.SortedSetRangeByRank(,Order.Ascending)) Console.Write(item + Console.WriteLine( 403_182@ Console.WriteLine(.Format(403_182@ of e is {0},db.SortedSet@R_403_182@(, Console.WriteLine(.Format(,db.SortedSetLength( Console.WriteLine(.Format(403_182@ of d increase by 1 is {0},db.SortedSetIncrement(,)));
  When you debug the above code,the results are as follow.

  The next post of this series is the basic opreation of List in Redis.Thanks for your reading.

猜你在找的Redis相关文章