org.redisson.config.SingleServerConfig Java Examples

The following examples show how to use org.redisson.config.SingleServerConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedissonConfig.java    From dk-foundation with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Bean
@ConditionalOnProperty(name="spring.redis.url")
RedissonClient redissonSingle() {
    Config config = new Config();
    SingleServerConfig serverConfig = config.useSingleServer()
            .setAddress(redisProperties.getUrl())
            .setDatabase(redisProperties.getDatabase());
    if (StringUtils.isNotBlank(redisProperties.getPassword())) {
        serverConfig.setPassword(redisProperties.getPassword());
    }
    if (redisProperties.getTimeout() != null) {
        serverConfig.setTimeout((int) redisProperties.getTimeout().getSeconds());
    }
    if (redisProperties.getJedis().getPool() != null) {
        serverConfig.setConnectionPoolSize(redisProperties.getJedis().getPool().getMaxActive())
                .setConnectionMinimumIdleSize(redisProperties.getJedis().getPool().getMinIdle());
    }

    return Redisson.create(config);
}
 
Example #2
Source File: RedissonTest.java    From java-tutorial with MIT License 6 votes vote down vote up
@Test
public void test() throws InterruptedException {
    Config config = new Config();
    SingleServerConfig singleServerConfig = config.useSingleServer();
    singleServerConfig.setAddress(redssionProperties.getAddress());
    singleServerConfig.setPassword(redssionProperties.getPassword());

    RedissonClient redissonClient = RedisUtils.getInstance().getRedisson(config);
    RBucket<Object> rBucket = RedisUtils.getInstance().getRBucket(redissonClient, "key");

    System.out.println(rBucket.get());
    while (true) {
        RLock lock = redissonClient.getLock("com.lock");
        lock.tryLock(0, 1, TimeUnit.SECONDS);
        try {
            System.out.println("执行");
        } finally {
            lock.unlock();
        }
    }


}
 
Example #3
Source File: RedissonAutoConfiguration.java    From spring-boot-seckill with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 单机模式自动装配
 * @return
 */
@Bean
@ConditionalOnProperty(name="redisson.address")
RedissonClient redissonSingle() {
    Config config = new Config();
    SingleServerConfig serverConfig = config.useSingleServer()
            .setAddress(redssionProperties.getAddress())
            .setTimeout(redssionProperties.getTimeout())
            .setConnectionPoolSize(redssionProperties.getConnectionPoolSize())
            .setConnectionMinimumIdleSize(redssionProperties.getConnectionMinimumIdleSize());
    if(StringUtils.isNotBlank(redssionProperties.getPassword())) {
        serverConfig.setPassword(redssionProperties.getPassword());
    }

    return Redisson.create(config);
}
 
Example #4
Source File: RedisInitializer.java    From tio-starters with MIT License 5 votes vote down vote up
private Config getSingleServerConfig() {
    Config config = new Config();
    String address = redisConfig.toString();
    SingleServerConfig singleServerConfig = config.useSingleServer()
            .setAddress(address)
            .setConnectionPoolSize(redisConfig.getPoolSize())
            .setConnectionMinimumIdleSize(redisConfig.getMinimumIdleSize());
    if (redisConfig.hasPassword()) {
        singleServerConfig.setPassword(redisConfig.getPassword());
    }
    config.setCodec(new FstCodec());
    //默认情况下,看门狗的检查锁的超时时间是30秒钟
    config.setLockWatchdogTimeout(1000 * 30);
    return config;
}
 
Example #5
Source File: RedissonManager.java    From SnowJena with Apache License 2.0 5 votes vote down vote up
@Bean
public RedissonClient redissonClient() {
    Config config = new Config();
    SingleServerConfig singleServerConfig = config.useSingleServer()
            .setAddress("redis://" + redisProperties.getHost() + ":" + redisProperties.getPort());
    if (redisProperties.getPassword() != null && !"".equals(redisProperties.getPassword())) {
        singleServerConfig.setPassword(redisProperties.getPassword());
    }
    return Redisson.create(config);
}
 
Example #6
Source File: RedisAtomConfig.java    From Milkomeda with MIT License 5 votes vote down vote up
@Bean
@ConditionalOnProperty(prefix = "milkomeda.atom.redis", name = "use-cluster", havingValue = "false", matchIfMissing = true)
public RedissonClient redissonClient() {
    Config config = new Config();
    String redisUrl = String.format("redis://%s:%d", redisProperties.getHost(), redisProperties.getPort());
    SingleServerConfig singleServerConfig = config.useSingleServer();
    singleServerConfig
            .setAddress(redisUrl)
            .setPassword(redisProperties.getPassword())
            .setDatabase(redisProperties.getDatabase());
    if (redisProperties.getTimeout() != null) {
        singleServerConfig.setTimeout((int) redisProperties.getTimeout().toMillis());
    }
    return Redisson.create(config);
}
 
Example #7
Source File: RedissonAutoConfiguration.java    From gpmall with Apache License 2.0 5 votes vote down vote up
@Bean
RedissonClient redissonClient() {
    Config config = new Config();
    String node = redissonProperties.getAddress();
    node = node.startsWith("redis://") ? node : "redis://" + node;
    SingleServerConfig serverConfig = config.useSingleServer()
            .setAddress(node)
            .setTimeout(redissonProperties.getTimeout())
            .setConnectionMinimumIdleSize(redissonProperties.getPool().getMinIdle());
    if (StringUtils.isNotBlank(redissonProperties.getPassword())) {
        serverConfig.setPassword(redissonProperties.getPassword());
    }
    return Redisson.create(config);
}
 
Example #8
Source File: RedissonAutoConfiguration.java    From SpringBoot2.0 with Apache License 2.0 5 votes vote down vote up
/**
 * 单机模式自动装配
 * @return
 */
@Bean
@ConditionalOnProperty(name = "redisson.address")
public RedissonClient redissonSingle() {
    Config config = new Config();
    SingleServerConfig serverConfig = config.useSingleServer()
            .setAddress(redssionProperties.getAddress())
            .setTimeout(redssionProperties.getTimeout())
            .setConnectionPoolSize(redssionProperties.getConnectionPoolSize())
            .setConnectionMinimumIdleSize(redssionProperties.getConnectionMinimumIdleSize());
    return Redisson.create(config);
}
 
Example #9
Source File: RedisConfig.java    From earth-frost with Apache License 2.0 5 votes vote down vote up
/**
 * 单机模式
 *
 * @param redissonProperties redisson配置
 * @return client
 */
static RedissonClient redissonSingle(RedissonProperties redissonProperties) {
  Config config = new Config();
  SingleServerConfig serverConfig = config.useSingleServer()
      .setAddress(redissonProperties.getAddress()).setTimeout(redissonProperties.getTimeout())
      .setConnectionPoolSize(redissonProperties.getConnectionPoolSize())
      .setConnectionMinimumIdleSize(redissonProperties.getConnectionMinimumIdleSize());

  if (redissonProperties.getPassword() != null && redissonProperties.getPassword().length() > 0) {
    serverConfig.setPassword(redissonProperties.getPassword());
  }

  return Redisson.create(config);
}
 
Example #10
Source File: TokenServiceImpl.java    From java-tutorial with MIT License 5 votes vote down vote up
public TokenServiceImpl() {
    Config config = new Config();
    SingleServerConfig singleServerConfig = config.useSingleServer();
    singleServerConfig.setAddress(redssionProperties.getAddress());
    singleServerConfig.setPassword(redssionProperties.getPassword());

    redissonClient = RedisUtils.getInstance().getRedisson(config);
}
 
Example #11
Source File: SeedLockConfiguration.java    From seed with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initRedissonClientList(){
    LogUtil.getLogger().info("RedissonClientList init beginning...");
    //空判断:防止接入SpringCloud后二次初始化
    if(!redissonClientList.isEmpty()){
        LogUtil.getLogger().info("RedissonClientList has inited, skip...");
        return;
    }
    for(String node : nodes){
        Config config = new Config();
        if(lockWatchdogTimeout > 0){
            config.setLockWatchdogTimeout(lockWatchdogTimeout);
        }
        SingleServerConfig singleConfig = config.useSingleServer().setAddress(node);
        if(connectionMinimumIdleSize > 0){
            singleConfig.setConnectionMinimumIdleSize(connectionMinimumIdleSize);
        }
        if(connectionPoolSize > 0){
            singleConfig.setConnectionPoolSize(connectionPoolSize);
        }
        if(connectTimeout > 0){
            singleConfig.setConnectTimeout(connectTimeout);
        }
        if(database > 0){
            singleConfig.setDatabase(database);
        }
        if(StringUtils.isNotBlank(password)){
            singleConfig.setPassword(password);
        }
        redissonClientList.add(Redisson.create(config));
        LogUtil.getLogger().info("RedissonClientList init on {}", node);
    }
    LogUtil.getLogger().info("RedissonClientList init end...");
}
 
Example #12
Source File: RedisInitializer.java    From t-io with Apache License 2.0 5 votes vote down vote up
private Config getSingleServerConfig() {
    Config config = new Config();
    String address = redisConfig.toString();
    SingleServerConfig singleServerConfig = config.useSingleServer()
            .setAddress(address)
            .setConnectionPoolSize(redisConfig.getPoolSize())
            .setConnectionMinimumIdleSize(redisConfig.getMinimumIdleSize());
    if (redisConfig.hasPassword()) {
        singleServerConfig.setPassword(redisConfig.getPassword());
    }
    config.setCodec(new FstCodec());
    //默认情况下,看门狗的检查锁的超时时间是30秒钟
    config.setLockWatchdogTimeout(1000 * 30);
    return config;
}
 
Example #13
Source File: SingleConnectionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
private static MasterSlaveServersConfig create(SingleServerConfig cfg) {
    MasterSlaveServersConfig newconfig = new MasterSlaveServersConfig();
    
    newconfig.setPingConnectionInterval(cfg.getPingConnectionInterval());
    newconfig.setSslEnableEndpointIdentification(cfg.isSslEnableEndpointIdentification());
    newconfig.setSslProvider(cfg.getSslProvider());
    newconfig.setSslTruststore(cfg.getSslTruststore());
    newconfig.setSslTruststorePassword(cfg.getSslTruststorePassword());
    newconfig.setSslKeystore(cfg.getSslKeystore());
    newconfig.setSslKeystorePassword(cfg.getSslKeystorePassword());
    
    newconfig.setRetryAttempts(cfg.getRetryAttempts());
    newconfig.setRetryInterval(cfg.getRetryInterval());
    newconfig.setTimeout(cfg.getTimeout());
    newconfig.setPassword(cfg.getPassword());
    newconfig.setUsername(cfg.getUsername());
    newconfig.setDatabase(cfg.getDatabase());
    newconfig.setClientName(cfg.getClientName());
    newconfig.setMasterAddress(cfg.getAddress());
    newconfig.setMasterConnectionPoolSize(cfg.getConnectionPoolSize());
    newconfig.setSubscriptionsPerConnection(cfg.getSubscriptionsPerConnection());
    newconfig.setSubscriptionConnectionPoolSize(cfg.getSubscriptionConnectionPoolSize());
    newconfig.setConnectTimeout(cfg.getConnectTimeout());
    newconfig.setIdleConnectionTimeout(cfg.getIdleConnectionTimeout());
    newconfig.setDnsMonitoringInterval(cfg.getDnsMonitoringInterval());

    newconfig.setMasterConnectionMinimumIdleSize(cfg.getConnectionMinimumIdleSize());
    newconfig.setSubscriptionConnectionMinimumIdleSize(cfg.getSubscriptionConnectionMinimumIdleSize());
    newconfig.setReadMode(ReadMode.MASTER);
    newconfig.setSubscriptionMode(SubscriptionMode.MASTER);
    newconfig.setKeepAlive(cfg.isKeepAlive());
    
    return newconfig;
}
 
Example #14
Source File: SingleConnectionManager.java    From redisson with Apache License 2.0 4 votes vote down vote up
public SingleConnectionManager(SingleServerConfig cfg, Config config, UUID id) {
    super(create(cfg), config, id);
}
 
Example #15
Source File: SpringNamespaceWikiTest.java    From redisson with Apache License 2.0 4 votes vote down vote up
@Test
public void testSingleWithPlaceholder() throws Exception {        
    RedisRunner.RedisProcess run = new RedisRunner()
            .requirepass("do_not_use_if_it_is_not_set")
            .nosave()
            .randomDir()
            .run();
    System.setProperty("redisson.redisAddress", run.getRedisServerAddressAndPort());
    System.setProperty("redisson.threads", "1");
    System.setProperty("redisson.nettyThreads", "2");
    System.setProperty("redisson.codecRef", "myCodec");
    System.setProperty("redisson.useLinuxNativeEpoll", "false");
    System.setProperty("redisson.redissonReferenceEnabled", "false");
    System.setProperty("redisson.codecProviderRef", "myCodecProvider");
    System.setProperty("redisson.resolverProviderRef", "myResolverProvider");
    System.setProperty("redisson.executorRef", "myExecutor");
    System.setProperty("redisson.eventLoopGroupRef", "myEventLoopGroup");
    System.setProperty("redisson.idleConnectionTimeout", "10000");
    System.setProperty("redisson.pingTimeout", "20000");
    System.setProperty("redisson.connectTimeout", "30000");
    System.setProperty("redisson.timeout", "40000");
    System.setProperty("redisson.retryAttempts", "5");
    System.setProperty("redisson.retryInterval", "60000");
    System.setProperty("redisson.reconnectionTimeout", "70000");
    System.setProperty("redisson.failedAttempts", "8");
    System.setProperty("redisson.password", "do_not_use_if_it_is_not_set");
    System.setProperty("redisson.subscriptionsPerConnection", "10");
    System.setProperty("redisson.clientName", "client_name");
    System.setProperty("redisson.sslEnableEndpointIdentification", "true");
    System.setProperty("redisson.sslProvider", "JDK");
    System.setProperty("redisson.sslTruststore", "/tmp/truststore.p12");
    System.setProperty("redisson.sslTruststorePassword", "not_set");
    System.setProperty("redisson.sslKeystore", "/tmp/keystore.p12");
    System.setProperty("redisson.sslKeystorePassword", "not_set");
    System.setProperty("redisson.subscriptionConnectionMinimumIdleSize", "11");
    System.setProperty("redisson.subscriptionConnectionPoolSize", "12");
    System.setProperty("redisson.connectionMinimumIdleSize", "13");
    System.setProperty("redisson.connectionPoolSize", "14");
    System.setProperty("redisson.database", "15");
    System.setProperty("redisson.dnsMonitoring", "false");
    System.setProperty("redisson.dnsMonitoringInterval", "80000");
    
    try {
        ClassPathXmlApplicationContext context
                = new ClassPathXmlApplicationContext("classpath:org/redisson/spring/support/namespace_wiki_single_with_placeholder.xml");
        RedissonClient redisson = context.getBean("myId", RedissonClient.class);
        assertNotNull(redisson);
        Config config = redisson.getConfig();
        assertEquals(1, config.getThreads());
        assertEquals(2, config.getNettyThreads());
        assertSame(context.getBean("myCodec", Codec.class), config.getCodec());
        assertEquals(false, config.isReferenceEnabled());
        assertSame(context.getBean("myExecutor", Executor.class), config.getExecutor());
        assertSame(context.getBean("myEventLoopGroup", EventLoopGroup.class), config.getEventLoopGroup());
        Method method = Config.class.getDeclaredMethod("getSingleServerConfig", (Class<?>[]) null);
        method.setAccessible(true);
        SingleServerConfig single = (SingleServerConfig) method.invoke(config, (Object[]) null);
        assertEquals(10000, single.getIdleConnectionTimeout());
        assertEquals(30000, single.getConnectTimeout());
        assertEquals(40000, single.getTimeout());
        assertEquals(5, single.getRetryAttempts());
        assertEquals(60000, single.getRetryInterval());
        assertEquals("do_not_use_if_it_is_not_set", single.getPassword());
        assertEquals(10, single.getSubscriptionsPerConnection());
        assertEquals("client_name", single.getClientName());
        assertEquals(11, single.getSubscriptionConnectionMinimumIdleSize());
        assertEquals(12, single.getSubscriptionConnectionPoolSize());
        assertEquals(13, single.getConnectionMinimumIdleSize());
        assertEquals(14, single.getConnectionPoolSize());
        assertEquals(15, single.getDatabase());
        assertEquals(80000, single.getDnsMonitoringInterval());
        ((ConfigurableApplicationContext) context).close();
    } finally {
        run.stop();
    }
}
 
Example #16
Source File: SeimiConfig.java    From SeimiCrawler with Apache License 2.0 2 votes vote down vote up
/**
 * Init single server configuration.
 *
 *  config.useSingleServer().setAddress("redis://myredisserver:6379");
 *
 * @return SingleServerConfig
 */
public SingleServerConfig redisSingleServer() {
    enableDistributedQueue();
    return redissonConfig.useSingleServer();
}