org.redisson.config.Config.useClusterServers()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(608)

本文整理了Java中org.redisson.config.Config.useClusterServers()方法的一些代码示例,展示了Config.useClusterServers()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.useClusterServers()方法的具体详情如下:
包路径:org.redisson.config.Config
类名称:Config
方法名:useClusterServers

Config.useClusterServers介绍

[英]Init cluster servers configuration
[中]初始化群集服务器配置

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Init cluster servers configuration
 *
 * @return config
 */
public ClusterServersConfig useClusterServers() {
  return useClusterServers(new ClusterServersConfig());
}

代码示例来源:origin: redisson/redisson

/**
 * Init cluster servers configuration
 *
 * @return config
 */
public ClusterServersConfig useClusterServers() {
  return useClusterServers(new ClusterServersConfig());
}

代码示例来源:origin: zhegexiaohuozi/SeimiCrawler

/**
 * Init cluster servers configuration
 *
 * config.useClusterServers()
 *     .setScanInterval(2000) // 集群状态扫描间隔时间,单位是毫秒
 *     //可以用"rediss://"来启用SSL连接
 *     .addNodeAddress("redis://127.0.0.1:7000", "redis://127.0.0.1:7001")
 *     .addNodeAddress("redis://127.0.0.1:7002");
 *
 * @return config
 */
public ClusterServersConfig redisClusterServers() {
  enableDistributedQueue();
  return redissonConfig.useClusterServers();
}

代码示例来源:origin: redisson/redisson

config.useClusterServers()
  .addNodeAddress(nodes)
  .setConnectTimeout(timeout)

代码示例来源:origin: org.redisson/redisson

/**
 * Init cluster servers configuration
 *
 * @return config
 */
public ClusterServersConfig useClusterServers() {
  return useClusterServers(new ClusterServersConfig());
}

代码示例来源:origin: TaXueWWL/redis-distributed-lock

@Override
  public Config createRedissonConfig(String address) {
    Config config = new Config();
    try {
      String[] addrTokens = address.split(",");
      /**设置cluster节点的服务IP和端口*/
      for (int i = 0; i < addrTokens.length; i++) {
        config.useClusterServers()
            .addNodeAddress(GlobalConstant.REDIS_CONNECTION_PREFIX.getConstant_value() + addrTokens[i]);
      }
      LOGGER.info("初始化[cluster]方式Config,redisAddress:" + address);
    } catch (Exception e) {
      LOGGER.error("cluster Redisson init error", e);
      e.printStackTrace();
    }
    return config;
  }
}

代码示例来源:origin: heibaiying/spring-samples-for-all

public RedissonClient redissonClient() {
  Config config = new Config();
  config.useClusterServers()
      .setScanInterval(2000) // 集群状态扫描间隔时间,单位是毫秒
      //可以用"rediss://"来启用SSL连接
      .addNodeAddress("redis://127.0.0.1:6379", "redis://127.0.0.1:6380")
      .addNodeAddress("redis://127.0.0.1:6381");
  return Redisson.create(config);
}

代码示例来源:origin: huangjian888/jeeweb-mybatis-springboot

public RedissonClient getRedissonClient() {
  Config config = new Config();
  if (StringUtils.isNotBlank(address)) {
    SingleServerConfig serverConfig = config.useSingleServer().setAddress(address);
    if (StringUtils.isNotBlank(password)) {
      serverConfig.setPassword(password);
    }
    serverConfig.setTimeout(timeout);
  } else if (!nodeAddresses.isEmpty()) {
    ClusterServersConfig serverConfig = config.useClusterServers()
        .addNodeAddress(nodeAddresses.toArray(new String[] {}));
    if (StringUtils.isNotBlank(password)) {
      serverConfig.setPassword(password);
    }
    serverConfig.setTimeout(timeout);
  } else if (masterAddress != null && !slaveAddresses.isEmpty()) {
    MasterSlaveServersConfig serverConfig = config.useMasterSlaveServers().setMasterAddress(masterAddress)
        .addSlaveAddress(slaveAddresses.toArray(new String[] {}));
    if (StringUtils.isNotBlank(password)) {
      serverConfig.setPassword(password);
    }
    serverConfig.setTimeout(timeout);
  }
  return Redisson.create(config);
}

代码示例来源:origin: kekingcn/spring-boot-klock-starter

@Bean(destroyMethod = "shutdown")
@ConditionalOnMissingBean
RedissonClient redisson() throws Exception {
  Config config = new Config();
  if(klockConfig.getClusterServer()!=null){
    config.useClusterServers().setPassword(klockConfig.getPassword())
        .addNodeAddress(klockConfig.getClusterServer().getNodeAddresses());
  }else {
    config.useSingleServer().setAddress(klockConfig.getAddress())
        .setDatabase(klockConfig.getDatabase())
        .setPassword(klockConfig.getPassword());
  }
  Codec codec=(Codec) ClassUtils.forName(klockConfig.getCodec(),ClassUtils.getDefaultClassLoader()).newInstance();
  config.setCodec(codec);
  config.setEventLoopGroup(new NioEventLoopGroup());
  return Redisson.create(config);
}

代码示例来源:origin: jzyong/game-server

/**
 * 连接服务器
 * 
 * @author JiangZhiYong
 * @QQ 359135103 2017年9月15日 下午3:36:06
 * @param configPath
 */
public static void connectRedis(String configPath) {
  if (redisson != null) {
    LOGGER.warn("Redisson客户端已经连接");
  }
  redissonClusterConfig = FileUtil.getConfigXML(configPath, "redissonClusterConfig.xml",
      RedissonClusterConfig.class);
  if (redissonClusterConfig == null) {
    LOGGER.warn("{}/redissonClusterConfig.xml文件不存在", configPath);
    System.exit(0);
  }
  Config config = new Config();
  config.setCodec(new FastJsonCodec());
  ClusterServersConfig clusterServersConfig = config.useClusterServers();
  clusterServersConfig.setScanInterval(redissonClusterConfig.getScanInterval()); // 集群状态扫描间隔时间,单位是毫秒
  // 可以用"rediss://"来启用SSL连接
  redissonClusterConfig.getNodes().forEach(url -> clusterServersConfig.addNodeAddress(url));
  clusterServersConfig.setReadMode(redissonClusterConfig.getReadMode());
  clusterServersConfig.setSubscriptionMode(redissonClusterConfig.getSubscriptionMode());
  redisson = Redisson.create(config);
}

代码示例来源:origin: youngMen1/JAVA-

nodeAddress.add(redisNode.getHost() + ":" + redisNode.getPort());
ClusterServersConfig serverConfig = config.useClusterServers()
    .addNodeAddress(nodeAddress.toArray(new String[] {}));
if (clusterConfig.getPassword().isPresent()) {

代码示例来源:origin: redisson/redisson-examples

public static void main(String[] args) {
  Config config = new Config();
  config.useClusterServers()
    .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003");
  
  RedissonClient redisson = Redisson.create(config);
  RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
  nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 1));
  RedissonNode node = RedissonNode.create(nodeConfig);
  node.start();
  RExecutorService e = redisson.getExecutorService("myExecutor");
  e.execute(new RunnableTask());
  e.submit(new CallableTask());
  
  e.shutdown();
  node.shutdown();
}

代码示例来源:origin: justlive1/earth-frost

/**
 * 集群模式
 * 
 * @param redissonProperties
 * @return client
 */
private RedissonClient redissonCluster(RedissonProperties redissonProperties) {
 Config config = new Config();
 ClusterServersConfig serverConfig =
   config.useClusterServers().addNodeAddress(redissonProperties.getNodeAddresses())
     .setTimeout(redissonProperties.getTimeout())
     .setScanInterval(redissonProperties.getScanInterval())
     .setSlaveConnectionPoolSize(redissonProperties.getSlaveConnectionPoolSize())
     .setMasterConnectionPoolSize(redissonProperties.getMasterConnectionPoolSize());
 if (redissonProperties.getPassword() != null && redissonProperties.getPassword().length() > 0) {
  serverConfig.setPassword(redissonProperties.getPassword());
 }
 return Redisson.create(config);
}

代码示例来源:origin: redisson/redisson-examples

public static void main(String[] args) {
  Config config = new Config();
  config.useClusterServers()
    .addNodeAddress("127.0.0.1:7001", "127.0.0.1:7002", "127.0.0.1:7003");
  
  RedissonClient redisson = Redisson.create(config);
  RedissonNodeConfig nodeConfig = new RedissonNodeConfig(config);
  nodeConfig.setExecutorServiceWorkers(Collections.singletonMap("myExecutor", 5));
  RedissonNode node = RedissonNode.create(nodeConfig);
  node.start();
  RScheduledExecutorService e = redisson.getExecutorService("myExecutor");
  e.schedule(new RunnableTask(), 10, TimeUnit.SECONDS);
  e.schedule(new CallableTask(), 4, TimeUnit.MINUTES);
  e.schedule(new RunnableTask(), CronSchedule.of("10 0/5 * * * ?"));
  e.schedule(new RunnableTask(), CronSchedule.dailyAtHourAndMinute(10, 5));
  e.schedule(new RunnableTask(), CronSchedule.weeklyOnDayAndHourAndMinute(12, 4, Calendar.MONDAY, Calendar.FRIDAY));
  
  e.shutdown();
  node.shutdown();
}

相关文章