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

  • 相关阅读:
    【分享】如何给视频码流添加PTS和用户自定义信息
    【分享】在MPSoC ZCU106单板的HDMI-Tx上基于eglfs_kms的运行QT应用程序
    检查Linux DRM显示设备ID的脚本
    【分享】更新的 AXI performance monitors (APM)测试工具
    window下安装clickhouse
    计算机组成原理学习
    FX DocuCentre S2110富士施乐打印机驱动
    打开网站出现Service Unavailable错误解决方法
    Java高德地图两点间距离、地理编码、逆地理编码
    IDEA运行Main报错Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.6.0:exec (default-cli) on project education: Command execution failed.
  • 原文地址:https://www.cnblogs.com/wjcx-sqh/p/13511580.html
Copyright © 2011-2022 走看看