zoukankan      html  css  js  c++  java
  • redis

    前面有简单学习过redis,此处扩展之.. 阿里云redis开发规范

    redis工具

    数据同步:redis-port

    big-key搜索

    参考:工具汇总

    命令行

    redis-cli --bigkeys
    

    find_bigkeys.py

    阿里云基于python工具,按key值长度

    python find_bigkey.py host port password
    

    rdb_bigkeys

    基于go实现的分析rdb文件查找big-key工具

    big-key删除

    //1、Hash删除: hscan + hdel
    public void delBigHash(String host, int port, String password, String bigHashKey) {
        Jedis jedis = new Jedis(host, port);
        if (!StringUtils.isBlank(password)) { jedis.auth(password); }
        ScanParams scanParams = new ScanParams().count(100);
        String cursor = "0";
        do {
            ScanResult<Entry<String, String>> scanResult = jedis.hscan(bigHashKey, cursor, scanParams);
            List<Entry<String, String>> entryList = scanResult.getResult();
            if (entryList != null && !entryList.isEmpty()) {
                for (Entry<String, String> entry : entryList) { jedis.hdel(bigHashKey, entry.getKey()); }
            }
            cursor = scanResult.getStringCursor();
        } while (!"0".equals(cursor));
    
        jedis.del(bigHashKey); //删除bigkey
    }
    //2、List删除: ltrim
    public void delBigList(String host, int port, String password, String bigListKey) {
        Jedis jedis = new Jedis(host, port);
        if (!StringUtils.isBlank(password)) { jedis.auth(password); }
        long llen = jedis.llen(bigListKey);
        int counter = 0, left = 100;
        while (counter < llen) {
            jedis.ltrim(bigListKey, left, llen); //每次从左侧截掉100个
            counter += left;
        }
        jedis.del(bigListKey); //最终删除key
    }
    //3、Set删除: sscan + srem
    public void delBigSet(String host, int port, String password, String bigSetKey) {
        Jedis jedis = new Jedis(host, port);
        if (!StringUtils.isBlank(password)) { jedis.auth(password); }
        ScanParams scanParams = new ScanParams().count(100);
        String cursor = "0";
        do {
            ScanResult<String> scanResult = jedis.sscan(bigSetKey, cursor, scanParams);
            List<String> memberList = scanResult.getResult();
            if (memberList != null && !memberList.isEmpty()) {
                for (String member : memberList) { jedis.srem(bigSetKey, member); }
            }
            cursor = scanResult.getStringCursor();
        } while (!"0".equals(cursor));
    
        jedis.del(bigSetKey);//删除bigkey
    }
    //4、SortedSet删除: zscan + zrem
    public void delBigZset(String host, int port, String password, String bigZsetKey) {
        Jedis jedis = new Jedis(host, port);
        if (!StringUtils.isBlank(password)) { jedis.auth(password); }
        ScanParams scanParams = new ScanParams().count(100);
        String cursor = "0";
        do {
            ScanResult<Tuple> scanResult = jedis.zscan(bigZsetKey, cursor, scanParams);
            List<Tuple> tupleList = scanResult.getResult();
            if (tupleList != null && !tupleList.isEmpty()) {
                for (Tuple tuple : tupleList) { jedis.zrem(bigZsetKey, tuple.getElement()); }
            }
            cursor = scanResult.getStringCursor();
        } while (!"0".equals(cursor));
     
        jedis.del(bigZsetKey); //删除bigkey
    }
    

    UNLINK
    Redis 4.0.0已提供UNLINK命令异步删除大key
    命令行:UNLINK key [key ...]

    热点key搜索

    命令行

    redis-cli --hotkeys
    

    monitor

    redis-faina

  • 相关阅读:
    c.vim
    Ubuntu18.04重装指南
    [TJOI2017]城市 【树的直径+暴力+优化】
    [Bzoj3696]化合物【暴力+树形Dp】
    [JLOI2015]战争调度【暴力+树形Dp】
    [Bzoj3743][Coci2015] Kamp【换根Dp】
    [POI2017]Sabota【观察+树形Dp】
    [CQOI2009]叶子的染色【性质+树形Dp】
    COCI2014/2015 Contest#1 D MAFIJA【基环树最大独立点集】
    [牛客网] 推箱子【离散,线段树区间覆盖】
  • 原文地址:https://www.cnblogs.com/wjcx-sqh/p/13511580.html
Copyright © 2011-2022 走看看