zoukankan      html  css  js  c++  java
  • Sorted sets

    Redis in Action JOSIAH L. CARLSON MANNING Shelter Island

    ZSETs offer the ability to store a mapping of members to scores (similar to the keys and values  of HASHes).  These  mappings  allow  us  to  manipulate  the  numeric  scores, and fetch and scan over both members and scores based on the sorted order of the scores.
    In chapter 1, we showed a brief example that used ZSETs as a way of sorting submitted articles based on time and how many up-votes they had received, and in chapter 2, we had an example that used ZSETs as a way of handling the expiration of old cookies. In this section, we’ll talk about commands that operate on ZSETs. You’ll learn how to  add  and  update  items  in ZSETs,  as  well  as  how  to  use  the ZSET  intersection  and union commands. When finished with this section, you’ll have a much clearer under-standing about how ZSETs work, which will help you to better understand what we did with them in chapter 1, and how we’ll use them in chapters 5, 6, and 7.

    conn.zadd('zset-key', 'a', 3, 'b', 2, 'c', 1);
    //ZADD key-name score member [score member ...]—Adds members with the given scores to the ZSET
    conn.zcard('zset-key');
    //ZCARD key-name—Returns the number of members in the ZSET -->Knowing how large a ZSET is can tell us in some cases if it’s necessary to trim our ZSET
    conn.zincrby('zset-key', 'c', 3);
    //ZINCRBY key-name increment member—Increments the member in the ZSET
    conn.zscore('zset-key', 'b');
    //ZSCORE key-name member—Returns the score of the member in the ZSET --->Fetching scores of individual members can be useful if we’ve been keeping counters or toplists
    conn.zrank('zset-key', 'c');
    //ZRANK key-name member—Returns the position of the given member in the ZSET
    conn.zcount('zset-key', 0, 3);
    //ZCOUNT key-name min max—Returns the number of members with scores between the provided minimum and maximum -->Counting the number of itemswith a given range of scores canbe quite useful for some tasks
    conn.zrem('zset-key', 'b');
    //ZREM key-name member [member ...]—Removes the members from the ZSET, returning the number of members that were removed --->Removing membersis as easy as adding them
    conn.zrange('zset-key', 0, -1, withscore=True);
    //ZRANGE key-name start stop [WITHSCORES]—Returns the members and optionally the scores for the members with ranks between start and stop --->For debugging, we usually fetch theentire ZSET with this ZRANGE call, but real use caseswill usually fetch items a relatively small group at a time
  • 相关阅读:
    Linux开机自动启动ORACLE设置
    Linux Oracle服务启动&停止脚本与开机自启动
    日志挖掘(logminer)
    通过Oracle补充日志,找到锁阻塞源头的SQL
    Oracle Supplemental 补全日志介绍
    修改oracle系统参数spfile导致数据库无法启动解决
    ORA-10997:another startup/shutdown operation of this instance in progress解决方法
    Oracle DataBase单实例使用ASM案例(1)--ASM基本概念
    误删除数据文件,数据库还没有关闭
    2013全国电子设计竞赛进入国赛的项目总结
  • 原文地址:https://www.cnblogs.com/rsapaper/p/5815952.html
Copyright © 2011-2022 走看看