74a4c263fcc677933585861795f6e3fc74b34354.svn-base 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package org.jeecg.boot.starter.lock.core.strategy.impl;
  2. import lombok.extern.slf4j.Slf4j;
  3. import org.apache.commons.lang3.StringUtils;
  4. import org.jeecg.boot.starter.lock.core.strategy.RedissonConfigStrategy;
  5. import org.jeecg.boot.starter.lock.prop.RedissonProperties;
  6. import org.jeecg.boot.starter.lock.enums.GlobalConstant;
  7. import org.redisson.config.Config;
  8. /**
  9. * 集群方式Redisson配置
  10. * cluster方式至少6个节点(3主3从)
  11. * 配置方式:127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6382,127.0.0.1:6383,127.0.0.1:6384
  12. *
  13. * @author zyf
  14. * @date 2020-11-11
  15. */
  16. @Slf4j
  17. public class ClusterRedissonConfigStrategyImpl implements RedissonConfigStrategy {
  18. @Override
  19. public Config createRedissonConfig(RedissonProperties redissonProperties) {
  20. Config config = new Config();
  21. try {
  22. String address = redissonProperties.getAddress();
  23. String password = redissonProperties.getPassword();
  24. String[] addrTokens = address.split(",");
  25. // 设置集群(cluster)节点的服务IP和端口
  26. for (int i = 0; i < addrTokens.length; i++) {
  27. config.useClusterServers().addNodeAddress(GlobalConstant.REDIS_CONNECTION_PREFIX + addrTokens[i]);
  28. if (StringUtils.isNotBlank(password)) {
  29. config.useClusterServers().setPassword(password);
  30. }
  31. }
  32. log.info("初始化集群方式Config,连接地址:" + address);
  33. } catch (Exception e) {
  34. log.error("集群Redisson初始化错误", e);
  35. e.printStackTrace();
  36. }
  37. return config;
  38. }
  39. }