@Override public List<String> handleCommonDefaultConfig(int port, int maxMemory) { List<String> configs = new ArrayList<String>(); for (RedisConfigEnum config : RedisConfigEnum.values()) { if (RedisConfigEnum.MAXMEMORY.equals(config)) { configs.add(config.getKey() + " " + String.format(config.getValue(), maxMemory)); } else if (RedisConfigEnum.DBFILENAME.equals(config) || RedisConfigEnum.APPENDFILENAME.equals(config) || RedisConfigEnum.PORT.equals(config)) { configs.add(config.getKey() + " " + String.format(config.getValue(), port)); } else if (RedisConfigEnum.DIR.equals(config)) { configs.add(config.getKey() + " " + MachineProtocol.DATA_DIR); } else if (RedisConfigEnum.AUTO_AOF_REWRITE_PERCENTAGE.equals(config)) { // 随机比例 auto-aof-rewrite-percentage int percent = 69 + new Random().nextInt(30); configs.add( config.getKey() + " " + String.format(RedisConfigEnum.AUTO_AOF_REWRITE_PERCENTAGE.getValue(), percent)); } else { configs.add(config.getKey() + " " + config.getValue()); } } return configs; }
@Override public List<String> handleCommonConfig(int port, int maxMemory) { List<InstanceConfig> instanceConfigList = getByType(ConstUtils.CACHE_REDIS_STANDALONE); if (CollectionUtils.isEmpty(instanceConfigList)) { return Collections.emptyList(); } List<String> configs = new ArrayList<String>(); for (InstanceConfig instanceConfig : instanceConfigList) { // 无效配置过滤 if (!instanceConfig.isEffective()) { continue; } String configKey = instanceConfig.getConfigKey(); String configValue = instanceConfig.getConfigValue(); if (StringUtils.isBlank(configValue)) { configValue = SPECIAL_EMPTY_STR; } if (RedisConfigEnum.MAXMEMORY.getKey().equals(configKey)) { configValue = String.format(configValue, maxMemory); } else if (RedisConfigEnum.DBFILENAME.getKey().equals(configKey) || RedisConfigEnum.APPENDFILENAME.getKey().equals(configKey) || RedisConfigEnum.PORT.getKey().equals(configKey)) { configValue = String.format(configValue, port); } else if (RedisConfigEnum.DIR.getKey().equals(configKey)) { configValue = MachineProtocol.DATA_DIR; } else if (RedisConfigEnum.AUTO_AOF_REWRITE_PERCENTAGE.getKey().equals(configKey)) { // 随机比例 auto-aof-rewrite-percentage int percent = 69 + new Random().nextInt(30); configValue = String.format(configValue, percent); } configs.add(combineConfigKeyValue(configKey, configValue)); } return configs; }
@Override public List<String> handleSentinelConfig( String masterName, String host, int port, int sentinelPort) { List<InstanceConfig> instanceConfigList = instanceConfigDao.getByType(ConstUtils.CACHE_REDIS_SENTINEL); if (CollectionUtils.isEmpty(instanceConfigList)) { return Collections.emptyList(); } List<String> configs = new ArrayList<String>(); for (InstanceConfig instanceConfig : instanceConfigList) { if (!instanceConfig.isEffective()) { continue; } String configKey = instanceConfig.getConfigKey(); String configValue = instanceConfig.getConfigValue(); if (StringUtils.isBlank(configValue)) { configValue = SPECIAL_EMPTY_STR; } if (RedisSentinelConfigEnum.PORT.getKey().equals(configKey)) { configValue = String.format(configValue, sentinelPort); } else if (RedisSentinelConfigEnum.MONITOR.getKey().equals(configKey)) { configValue = String.format(configValue, masterName, host, port); } else if (RedisSentinelConfigEnum.DOWN_AFTER_MILLISECONDS.getKey().equals(configKey) || RedisSentinelConfigEnum.FAILOVER_TIMEOUT.getKey().equals(configKey) || RedisSentinelConfigEnum.PARALLEL_SYNCS.getKey().equals(configKey)) { configValue = String.format(configValue, masterName); } else if (RedisConfigEnum.DIR.getKey().equals(configKey)) { configValue = MachineProtocol.DATA_DIR; } configs.add(combineConfigKeyValue(configKey, configValue)); } return configs; }