zoukankan      html  css  js  c++  java
  • 源码解读 zsetAdd

    https://github.com/antirez/redis/blob/6a6471aad5e4f8d6cbab677b918b14cdee416296/src/t_zset.c

        /* Update the sorted set according to its encoding. */
        if (zobj->encoding == OBJ_ENCODING_ZIPLIST) {
            unsigned char *eptr;
    
            if ((eptr = zzlFind(zobj->ptr,ele,&curscore)) != NULL) {
                /* NX? Return, same element already exists. */
                if (nx) {
                    *flags |= ZADD_NOP;
                    return 1;
                }
    
                /* Prepare the score for the increment if needed. */
                if (incr) {
                    score += curscore;
                    if (isnan(score)) {
                        *flags |= ZADD_NAN;
                        return 0;
                    }
                    if (newscore) *newscore = score;
                }
    
                /* Remove and re-insert when score changed. */
                if (score != curscore) {
                    zobj->ptr = zzlDelete(zobj->ptr,eptr);
                    zobj->ptr = zzlInsert(zobj->ptr,ele,score);
                    *flags |= ZADD_UPDATED;
                }
                return 1;
            } else if (!xx) {
                /* Optimize: check if the element is too large or the list
                 * becomes too long *before* executing zzlInsert. */
                zobj->ptr = zzlInsert(zobj->ptr,ele,score);
                if (zzlLength(zobj->ptr) > server.zset_max_ziplist_entries)
                    zsetConvert(zobj,OBJ_ENCODING_SKIPLIST);
                if (sdslen(ele) > server.zset_max_ziplist_value)
                    zsetConvert(zobj,OBJ_ENCODING_SKIPLIST);
                if (newscore) *newscore = score;
                *flags |= ZADD_ADDED;
                return 1;
            } else {
                *flags |= ZADD_NOP;
                return 1;
            }
    

      

  • 相关阅读:
    git push出现unpack failed: error Missing tree错误的解决方法
    Android N 分屏
    adb 查看最上层activity名字
    Ubuntu 切换JDK 版本
    Android的开机流程
    HTTP 协议中GET和POST到底有哪些区别(转)
    github爬虫100项目
    web攻击之xss(一)
    Kali-Dos洪水攻击之Hping3
    zipCrack-v1.1 工具介绍
  • 原文地址:https://www.cnblogs.com/rsapaper/p/10240962.html
Copyright © 2011-2022 走看看