Java Code Examples for org.springframework.data.redis.connection.RedisStandaloneConfiguration#setHostName()

The following examples show how to use org.springframework.data.redis.connection.RedisStandaloneConfiguration#setHostName() . 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: RedisConfig.java    From SpringMVC-Project with MIT License 8 votes vote down vote up
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(hostName);
    redisStandaloneConfiguration.setPort(port);

    GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
    poolConfig.setMaxIdle(maxIdle);
    poolConfig.setMinIdle(minIdle);
    poolConfig.setMaxWaitMillis(maxWaitMillis);
    poolConfig.setMaxTotal(maxTotal);

    LettucePoolingClientConfiguration lettucePoolingClientConfiguration = LettucePoolingClientConfiguration.builder()
            .commandTimeout(Duration.ofSeconds(10))
            .shutdownTimeout(Duration.ZERO)
            .poolConfig(poolConfig)
            .build();

    LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisStandaloneConfiguration, lettucePoolingClientConfiguration);
    lettuceConnectionFactory.setShareNativeConnection(false);

    return lettuceConnectionFactory;
}
 
Example 2
Source File: RedisCacheFactory.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Override
protected RedisConnectionFactory createConnectionClient(String hostName, int port) {
	RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
	configuration.setHostName(hostName);
	configuration.setPort(port);
	if (JEDIS_AVAILABLE) {
		return new JedisConnectionFactory(configuration);
	}
	else if (LETTUCE_AVAILABLE) {
		return new LettuceConnectionFactory(configuration);
	}
	else {
		throw new IllegalArgumentException("No Jedis or lettuce client on classpath. "
				+ "Please add one of the implementation to your classpath");
	}
}
 
Example 3
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 6 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory2() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration ();
    redisStandaloneConfiguration.setHostName(redisProperties.getHost());
    redisStandaloneConfiguration.setPort(redisProperties.getPort());
    redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    redisStandaloneConfiguration.setDatabase(RedisDbIndexConst.DB_INDEX_2);
    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();

    JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
            jedisClientConfiguration.usePooling().poolConfig(jedisPoolConfig()).build());
    return factory;
}
 
Example 4
Source File: RedisAutoConfig.java    From unimall with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisStandaloneConfiguration lockRedisConfig() {
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
    config.setHostName(host);
    config.setPassword(RedisPassword.of(password));
    config.setPort(port);
    config.setDatabase(database);
    return config;
}
 
Example 5
Source File: InstallRemote.java    From jeesupport with MIT License 5 votes vote down vote up
@RemoteMethod
public void redis( String _host, int _port, String _password, int _db ) throws Exception{
    try{
        RedisConfig rc = new RedisConfig();

        RedisStandaloneConfiguration rsc = rc.redisStandaloneConfiguration();
        rsc.setHostName( _host );
        rsc.setPort( _port );
        rsc.setPassword( _password );
        rsc.setDatabase( _db );

        LettuceConnectionFactory lcf = ( LettuceConnectionFactory )
                rc.connectionFactory( rsc, rc.lettucePoolConfig( rc.clientOptions(), rc.clientResources() ) );
        lcf.setDatabase( _db );
        lcf.afterPropertiesSet();

        sDB.changeDatabase( lcf );

        Test t = new Test( RandomUtil.s_random_integer( 100 ) );
        sDB.insert( t );
        sDB.delete( t );

        installConfig.installRedis( _host, _port,_password, _db );
    }catch ( Exception e ){
        installConfig.installFailure( InstallConfig.InstallRedisSucc );
        throw new Exception( "连接失败" );
    }
}
 
Example 6
Source File: RedisConfig.java    From spring-boot-start-current with Apache License 2.0 5 votes vote down vote up
@Bean
  public RedisConnectionFactory redisConnectionFactory () {
RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration(  );
standaloneConfig.setHostName( host );
standaloneConfig.setPort( port );
standaloneConfig.setPassword( RedisPassword.of( password ) );
standaloneConfig.setDatabase( database );
      return new JedisConnectionFactory(standaloneConfig);
  }
 
Example 7
Source File: RedisConfig.java    From FEBS-Security with Apache License 2.0 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(host);
    redisStandaloneConfiguration.setPort(port);
    redisStandaloneConfiguration.setPassword(RedisPassword.of(password));
    redisStandaloneConfiguration.setDatabase(database);

    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();
    jedisClientConfiguration.connectTimeout(Duration.ofMillis(timeout));
    jedisClientConfiguration.usePooling();
    return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration.build());
}
 
Example 8
Source File: RedisCacheConfig.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Bean
public LettuceConnectionFactory redisConnectionFactory() {
    RedisStandaloneConfiguration redisConf = new RedisStandaloneConfiguration();
    redisConf.setHostName(env.getProperty("spring.redis.host"));
    redisConf.setPort(Integer.parseInt(env.getProperty("spring.redis.port")));
    redisConf.setPassword(RedisPassword.of(env.getProperty("spring.redis.password")));
    return new LettuceConnectionFactory(redisConf);
}
 
Example 9
Source File: RedisAutoConfig.java    From unimall with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisStandaloneConfiguration defaultRedisConfig() {
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
    config.setHostName(host);
    config.setPassword(RedisPassword.of(password));
    config.setPort(port);
    config.setDatabase(database);
    return config;
}
 
Example 10
Source File: CacheConfig.java    From ultimate-redis-boot with MIT License 5 votes vote down vote up
@Bean
public LettuceConnectionFactory redisConnectionFactory(CacheConfigurationProperties properties) {
    log.info("Redis (/Lettuce) configuration enabled. With cache timeout " + properties.getTimeoutSeconds() + " seconds.");

    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration();
    redisStandaloneConfiguration.setHostName(properties.getRedisHost());
    redisStandaloneConfiguration.setPort(properties.getRedisPort());
    return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
 
Example 11
Source File: RedisAutoConfig.java    From unimall with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisStandaloneConfiguration userRedisConfig() {
    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
    config.setHostName(host);
    config.setPassword(RedisPassword.of(password));
    config.setPort(port);
    config.setDatabase(database);
    return config;
}
 
Example 12
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory3() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration ();
    redisStandaloneConfiguration.setHostName(redisProperties.getHost());
    redisStandaloneConfiguration.setPort(redisProperties.getPort());
    redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    redisStandaloneConfiguration.setDatabase(RedisDbIndexConst.DB_INDEX_3);
    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();

    JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
            jedisClientConfiguration.usePooling().poolConfig(jedisPoolConfig()).build());
    return factory;
}
 
Example 13
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory1() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration ();
    redisStandaloneConfiguration.setHostName(redisProperties.getHost());
    redisStandaloneConfiguration.setPort(redisProperties.getPort());
    redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    redisStandaloneConfiguration.setDatabase(RedisDbIndexConst.DB_INDEX_1);
    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();

    JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
            jedisClientConfiguration.usePooling().poolConfig(jedisPoolConfig()).build());
    return factory;
}
 
Example 14
Source File: RedisConfig.java    From charging_pile_cloud with MIT License 5 votes vote down vote up
@Bean
@Primary
JedisConnectionFactory jedisConnectionFactory() {
    RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration ();
    redisStandaloneConfiguration.setHostName(redisProperties.getHost());
    redisStandaloneConfiguration.setPort(redisProperties.getPort());
    redisStandaloneConfiguration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    redisStandaloneConfiguration.setDatabase(RedisDbIndexConst.DB_INDEX_DEFAULT);
    JedisClientConfiguration.JedisClientConfigurationBuilder jedisClientConfiguration = JedisClientConfiguration.builder();

    JedisConnectionFactory factory = new JedisConnectionFactory(redisStandaloneConfiguration,
            jedisClientConfiguration.usePooling().poolConfig(jedisPoolConfig()).build());
    return factory;
}
 
Example 15
Source File: RedisConfiguration.java    From alcor with Apache License 2.0 5 votes vote down vote up
@Bean
LettuceConnectionFactory lettuceConnectionFactory() {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(redisHostName);
    configuration.setPort(redisHostPort);
    return new LettuceConnectionFactory(configuration);
}
 
Example 16
Source File: RedisConfiguration.java    From alcor with Apache License 2.0 5 votes vote down vote up
@Bean
LettuceConnectionFactory lettuceConnectionFactory() {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(redisHostName);
    configuration.setPort(redisHostPort);
    return new LettuceConnectionFactory(configuration);
}
 
Example 17
Source File: RedisConfig.java    From hot-crawler with MIT License 5 votes vote down vote up
@Bean
JedisConnectionFactory jedisConnectionFactory()
{
    RedisProperties properties = redisProperties();
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(properties.getHost());
    configuration.setPort(properties.getPort());
    configuration.setPassword(properties.getPassword());
    configuration.setDatabase(properties.getDatabase());
    return new JedisConnectionFactory(configuration);
}
 
Example 18
Source File: RedisConfiguration.java    From ad with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisStandaloneConfiguration standaloneConfiguration() {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(host);
    configuration.setPort(port);
    configuration.setDatabase(database);
    return configuration;
}
 
Example 19
Source File: IntegrationTest.java    From java-spring-cloud with Apache License 2.0 4 votes vote down vote up
public @Bean RedisConnectionFactory redisConnectionFactory() {
  RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
  config.setHostName(redis.getHost());
  config.setPort(redis.getBindPort());
  return new JedisConnectionFactory(config);
}
 
Example 20
Source File: IntegrationTestWithPrefixOperationName.java    From java-spring-cloud with Apache License 2.0 4 votes vote down vote up
public @Bean RedisConnectionFactory redisConnectionFactory() {
  RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
  config.setHostName(redis.getHost());
  config.setPort(redis.getBindPort());
  return new JedisConnectionFactory(config);
}