class RedisServerKeyValueAnalysisTask extends BaseTask {

    private String host;

    private int port;

    private long appId;

    private long auditId;

    /**
     * 扫描slave
     */
    private final static int SCAN_COUNT = 100;

    @Override
    public List<String> getTaskSteps() {<FILL_FUNCTION_BODY>}

    /**
     * 初始化参数
     *
     * @return
     */
    @Override
    public TaskFlowStatusEnum init() {
        super.init();

        appId = MapUtils.getLongValue(paramMap, TaskConstants.APPID_KEY);
        if (appId <= 0) {
            logger.error(marker, "task {} appId {} is wrong", taskId, appId);
            return TaskFlowStatusEnum.ABORT;
        }

        auditId = MapUtils.getLongValue(paramMap, TaskConstants.AUDIT_ID_KEY);
        if (auditId <= 0) {
            logger.error(marker, "task {} auditId {} is wrong", taskId, auditId);
            return TaskFlowStatusEnum.ABORT;
        }

        host = MapUtils.getString(paramMap, TaskConstants.HOST_KEY);
        if (StringUtils.isBlank(host)) {
            logger.error(marker, "task {} host is empty", taskId);
            return TaskFlowStatusEnum.ABORT;
        }

        port = MapUtils.getIntValue(paramMap, TaskConstants.PORT_KEY);
        if (port <= 0) {
            logger.error(marker, "task {} port {} is wrong", taskId, port);
            return TaskFlowStatusEnum.ABORT;
        }

        return TaskFlowStatusEnum.SUCCESS;
    }

    public TaskFlowStatusEnum checkIsRun() {
        if (!redisCenter.isRun(appId, host, port)) {
            logger.error(marker, "{} {}:{} is not run", appId, host, port);
            return TaskFlowStatusEnum.ABORT;
        }
        return TaskFlowStatusEnum.SUCCESS;
    }

    public TaskFlowStatusEnum keyValueAnalysis() {
        long startTime = System.currentTimeMillis();

        //本地结果集
        Map<ValueSizeDistriEnum, Long> valueSizeCountMap = new HashMap<ValueSizeDistriEnum, Long>();

        Jedis jedis = null;
        try {
            jedis = redisCenter.getJedis(appId, host, port);;
            jedis.readonly();
            
            long dbSize = jedis.dbSize();
            if (dbSize == 0) {
                logger.info(marker, "{} {}:{} dbsize is {}", appId, host, port, dbSize);
                return TaskFlowStatusEnum.SUCCESS;
            }
            logger.info(marker, "{} {}:{} total key is {} ", appId, host, port, dbSize);

            ScanParams scanParams = new ScanParams().count(SCAN_COUNT);
            byte[] cursor = "0".getBytes(Charset.forName("UTF-8"));

            long count = 0;
            int totalSplit = 10;
            int curSplit = 1;
            while (true) {
                try {
                    ScanResult<byte[]> scanResult = jedis.scan(cursor, scanParams);
                    cursor = scanResult.getCursorAsBytes();
                    List<byte[]> keyList = scanResult.getResult();

                    for (byte[] key : keyList) {
                        String debug = null;
                        try {
                            // key 可能不存在,报 ERR no such key
                            debug = jedis.debug(DebugParams.OBJECT(new String(key, Charset.forName("UTF-8"))));
                        } catch (JedisException e) {
                            logger.warn("debug-object-error: key={}", new String(key, Charset.forName("UTF-8")));
                            //ignore
                        }
                        if (StringUtils.isBlank(debug)) {
                            continue;
                        }
                        long valueBytes = NumberUtils.toLong(debug.split(" ")[4].split(":")[1]);
                        ValueSizeDistriEnum valueSizeDistriEnum = ValueSizeDistriEnum.getRightSizeBetween(valueBytes);
                        if (valueSizeDistriEnum == null) {
                            logger.warn("key {} valueBytes {} is wrong", key, valueBytes);
                            continue;
                        }
                        if (valueSizeCountMap.containsKey(valueSizeDistriEnum)) {
                            valueSizeCountMap.put(valueSizeDistriEnum, valueSizeCountMap.get(valueSizeDistriEnum) + 1);
                        } else {
                            valueSizeCountMap.put(valueSizeDistriEnum, 1L);
                        }
                    }
                    count += keyList.size();
                    if (count > dbSize / totalSplit * curSplit) {
                        logger.info(marker, "{} {}:{} has already anlysis {}% {} key ", appId, host, port,
                                curSplit * 10, count);
                        curSplit++;
                    }
                } catch (Exception e) {
                    logger.error(marker, e.getMessage(), e);
                } finally {
                    //防止无限循环
                    if (Arrays.equals("0".getBytes(Charset.forName("UTF-8")), cursor)) {
                        break;
                    }
                }
            }
            logger.info(marker, "{} {}:{} analysis key value size successfully, cost time is {} ms, total key is {}",
                    appId, host, port, (System.currentTimeMillis() - startTime), count);

            if (MapUtils.isNotEmpty(valueSizeCountMap)) {
                String keyValueSizeResultKey = ConstUtils.getRedisServerValueSizeKey(appId, auditId);
                for (Entry<ValueSizeDistriEnum, Long> entry : valueSizeCountMap.entrySet()) {
                    String valueSizeDistri = entry.getKey().getValue();
                    assistRedisService.zincrby(keyValueSizeResultKey, entry.getValue(), valueSizeDistri);
                    logger.info(marker, "{} {} {}:{} value size distri {} {}", keyValueSizeResultKey, appId, host, port,
                            valueSizeDistri, entry.getValue());
                }
            } else {
                logger.error(marker, "{} {}:{} value size distri is empty", appId, host, port);
            }

            return TaskFlowStatusEnum.SUCCESS;
        } catch (Exception e) {
            logger.error(marker, e.getMessage(), e);
            return TaskFlowStatusEnum.ABORT;
        } finally {
            if (jedis != null) {
                jedis.close();
            }
        }
    }

}

        List<String> taskStepList = new ArrayList<String>();
        taskStepList.add(TaskConstants.INIT_METHOD_KEY);
        // 检查实例是否运行
        taskStepList.add("checkIsRun");
        // key类型分析
        taskStepList.add("keyValueAnalysis");
        return taskStepList;
    
<methods>public non-sealed void <init>() ,public static java.lang.String generateMasterName(java.lang.String, int) ,public Map<java.lang.String,java.lang.Object> getParamMap() ,public abstract List<java.lang.String> getTaskSteps() ,public com.sohu.cache.task.constant.TaskStepFlowEnum.TaskFlowStatusEnum init() ,public void setParamMap(Map<java.lang.String,java.lang.Object>) <variables>public static final java.lang.String MARKER_NAME,private static final java.lang.String NUT_CRACKER_TEMPLATE_FILE,private static final java.lang.String NUT_CRACKER_TEMPLATE_NO_CPUIDX_FILE,private static final java.lang.String PIKA_TEMPLATE_FILE,private static final java.lang.String REDIS_COMMON_TEMPLATE_FILE,private static final java.lang.String REDIS_COMMON_TEMPLATE_NO_CPUIDX_FILE,private static final java.lang.String REDIS_MIGRATE_TOOL_TEMPLATE_FILE,private static final java.lang.String REDIS_PORT_TEMPLATE_FILE,protected com.sohu.cache.dao.AppAuditDao appAuditDao,protected com.sohu.cache.dao.AppDao appDao,protected com.sohu.cache.web.util.AppEmailUtil appEmailUtil,protected java.lang.String appEnvName,protected com.sohu.cache.web.service.AppService appService,protected com.sohu.cache.stats.app.AppStatsCenter appStatsCenter,protected com.sohu.cache.task.util.AppWechatUtil appWechatUtil,protected com.sohu.cache.redis.AssistRedisService assistRedisService,protected com.sohu.cache.dao.DiagnosticTaskRecordDao diagnosticTaskRecordDao,protected org.springframework.core.env.Environment environment,protected com.sohu.cache.dao.InstanceBigKeyDao instanceBigKeyDao,protected com.sohu.cache.dao.InstanceDao instanceDao,protected com.sohu.cache.stats.instance.InstanceDeployCenter instanceDeployCenter,protected com.sohu.cache.web.service.InstancePortService instancePortService,protected com.sohu.cache.dao.InstanceStatsDao instanceStatsDao,protected org.slf4j.Logger logger,protected com.sohu.cache.machine.MachineCenter machineCenter,protected com.sohu.cache.dao.MachineDao machineDao,protected com.sohu.cache.dao.MachineRelationDao machineRelationDao,protected com.sohu.cache.dao.MachineRoomDao machineRoomDao,protected com.sohu.cache.dao.MachineStatsDao machineStatsDao,public static final org.slf4j.Marker marker,protected com.sohu.cache.web.service.ModuleService moduleService,protected Map<java.lang.String,java.lang.Object> paramMap,protected com.sohu.cache.redis.RedisCenter redisCenter,protected com.sohu.cache.redis.RedisConfigTemplateService redisConfigTemplateService,protected com.sohu.cache.redis.RedisDeployCenter redisDeployCenter,protected com.sohu.cache.dao.ResourceDao resourceDao,protected com.sohu.cache.web.service.ResourceService resourceService,protected com.sohu.cache.ssh.SSHService sshService,protected long taskId,protected com.sohu.cache.task.TaskService taskService