redis sorted_set type

Indexed collections sortedset:

  Storage requirements: data ordering conducive to efficient data show the need to provide a way can be ordered according to their feature
  storage structure required: new storage model, the data can be saved sortable
  sorted_set Type: storage structure is set on the basis of Add sortable fields are associated with each element of a fraction of a field type double.

    It is to redis from small to large order of the set by scores of members of the field.

  1. Storage: Key score1 Zadd the member1 [member2 is score2]
      Zadd mysort 60 zhangsan
      Zadd mysort 50 Lisi
      Zadd mysort 80 wangwu
  2. Get: zrange key start stop [WITHSCORES] zrevrange key start stop [WITHSCORES] Reverse ranking score
      zrange mysort 0 - 1

      zrange mysort 0 -1 withscores
  3. 删除:zrem key member [member ...]
      zrem mysort lisi

  4. Data acquisition conditional:

    zrangebyscore key min max [WITHSCORES] [LIMIT offset count]
    zrevrangebyscore key max min [WITHSCORES]

  5. Conditions delete the data:

    zremrangebyrank key start stop
    zremrangebyscore key min max

    Note:
      min max and conditions for the search query defining
      start and stop for defining the scope of the query, the role of the index, the index indicates the start and end
      offset count for defining the scope of a query, the query results in the effect, indicating the start position of the data bus and the amount

  6. Get the total set of data

    zcard key
    zcount key min max

  7. The set intersection and union operations

    zinterstore destination numkeys key [key ...] numkeys number of the sets to be operated, after a specified number of key and it is equal to the back
    zunionstore destination numkeys key [key ...]

  Extended operation types of data sorted_set

    Business scene:

      Guangdong voted Ten Outstanding Young, all kinds of arts talent audition voting
      various resources website TOP10 (movies, songs, documents, e-business, games, etc.)
      chat room activity statistics
      gaming friends intimacy

    Business Analysis: Sort establish the basis for all participating rankings resources

    solution:

      Obtaining data corresponding index (ranking)

        zrank key member
        zrevrank key member

      score value acquisition and modification

        zscore key member
        zincrby key increment member

      

   Note sorted_set type of data manipulation

    score is stored in the data storage 64, if it is an integer in the range of ~ 9007199254740992. -9,007,199,254,740,992
    score stored data may be double the value of a double-precision, double precision floating point based on the feature, the precision may be lost, you should be careful when using
    sorted_set underlying storage is set based structure, so that the data can not be repeated, if repeated additions of the same data, score values will be overwritten repeatedly, last modified retention results

Guess you like

Origin www.cnblogs.com/roadlandscape/p/12410925.html