Leilin Peng Share: Redis ordered collection (sorted set)

  Redis ordered set and the same collection is also a set of string type elements, and does not allow duplicate members.

  The difference is that a double score will be associated with each type of element. It is to redis from small to large order of collection of member passing score.

  Members of the ordered set is unique, but the score (score) it can be repeated.

  Collection is achieved through a hash table, so add, delete, search complexity is O (1). The maximum number of members for the collection 232--1 (4,294,967,295, each set can store 40 million members).

  Examples

  redis 127.0.0.1:6379> ZADD coderctokey first redis

  (integer) 1

  redis 127.0.0.1:6379> ZADD coderctokey 2 mongodb

  (integer) 1

  redis 127.0.0.1:6379> mysql 3 ZADD coderctokey

  (integer) 1

  redis 127.0.0.1:6379> mysql 3 ZADD coderctokey

  (integer) 0

  redis 127.0.0.1:6379> 4 mysql ZADD coderctokey

  (integer) 0

  redis 127.0.0.1:6379> ZRANGE coderctokey 0 10 WITHSCORES

  1) "redis"

  2) "1"

  3) "mongodb"

  4) "2"

  5) "mysql"

  6) "4"

  In the above example we command ZADD adds three to the ordered set of values ​​and associated redis in the score.

  Redis ordered set of command

  The following table lists the basic commands redis ordered set:

  Number and description of command

  1ZADD key score1 member1 [score2 member2]

  Adding to the ordered set of one or more members, or update an existing member of the score

  2ZCARD key

  Gets the number of members of the ordered set

  3ZCOUNT key min max

  Calculates the number of members in the interval score ordered set

  4ZINCRBY key increment member

  An ordered set of plus points for designated members of the increment increment

  5ZINTERSTORE destination numkeys key [key ...]

  Calculation given one or more of the ordered set of intersections and the result set stored in the new key in the ordered set

  6ZLEXCOUNT key min max

  Calculate the number of members within the range specified in the dictionary ordered set

  7ZRANGE key start stop [WITHSCORES]

  By indexing interval returned an ordered set of members in the synthesis of the designated section

  8ZRANGEBYLEX key min max [LIMIT offset count]

  Back to Members through an ordered set of intervals dictionary

  9ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT]

  Back to Members within the specified range by an ordered set of scores

  10ZRANK key member

  Returns the index of an ordered set of specified members

  11ZREM key member [member ...]

  Removal of an ordered set of one or more members

  12ZREMRANGEBYLEX key min max

  Remove all members of a given ordered set of intervals dictionary

  13ZREMRANGEBYRANK key start stop

  All members of the removed ordered set of rankings given interval

  14ZREMRANGEBYSCORE key min max

  All members of the removed ordered set given score range

  15ZREVRANGE key start stop [WITHSCORES]

  Return ordered set of members within the specified range, through the index, scores from high in the end

  16ZREVRANGEBYSCORE key max min [WITHSCORES]

  Return ordered set members in the specified range of scores, scores from high to low sort

  17ZREVRANK key member

  Return ranking members of the specified sorted set, ordered set point value decreasing by members (descending) Sort

  18ZSCORE key member

  Return an ordered set, members of the fractional value

  19ZUNIONSTORE destination numkeys key [key ...]

  Calculation given one or more ordered sets and sets, and stores the new key in

  20ZSCAN key cursor [MATCH pattern] [COUNT count]

  Iteration ordered set of elements (including elements and element members scores)

  (Editor: Leilin Peng Source: network intrusion deleted)

Guess you like

Origin www.cnblogs.com/linpeng1/p/11276592.html