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

The following examples show how to use org.springframework.data.redis.connection.RedisStandaloneConfiguration#setPassword() . 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 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 2
Source File: HerokuRedisConfig.java    From spring-redis-websocket with Apache License 2.0 5 votes vote down vote up
@SneakyThrows
private LettuceConnectionFactory lettuceConnectionFactory() {
	String redisUrl = System.getenv("REDIS_URL");
	URI redistogoUri = new URI(redisUrl);
	RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redistogoUri.getHost(), redistogoUri.getPort());
	redisStandaloneConfiguration.setPassword(redistogoUri.getUserInfo().split(":", 2)[1]);
	return new LettuceConnectionFactory(redisStandaloneConfiguration);
}
 
Example 3
Source File: RedisConfiguration.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public LettuceConnectionFactory lettuceConnectionFactory()
{
    LettuceClientConfigurationBuilder builder = LettuceClientConfiguration.builder();
    if(Boolean.parseBoolean( (String) redisSslEnabled().getObject()))
    {
        builder.useSsl();
    }
    LettuceClientConfiguration clientConfiguration = builder.build();
    RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration();
    standaloneConfig.setHostName( (String) redisHost().getObject() );
    standaloneConfig.setPassword( (String) redisPassword().getObject() );
    standaloneConfig.setPort( Integer.parseInt( (String) redisPort().getObject() ) );
    return new LettuceConnectionFactory( standaloneConfig, clientConfiguration );
}
 
Example 4
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 5
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 6
Source File: Redis.java    From syncer with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public LettuceConnectionFactory getConnectionFactory() {
  if (clusterConnection.valid()) {
    return new LettuceConnectionFactory(clusterConnection.getConfig());
  }
  if (connection.valid()) {
    RedisStandaloneConfiguration standaloneConfig = new RedisStandaloneConfiguration(
        connection.getAddress(),
        connection.getPort());
    if (!connection.noPassword()) {
      standaloneConfig.setPassword(RedisPassword.of(connection.getPassword()));
    }
    return new LettuceConnectionFactory(standaloneConfig);
  }
  throw new InvalidConfigException("No valid connection configured");
}
 
Example 7
Source File: L3RedisCacheConfig.java    From x7 with Apache License 2.0 5 votes vote down vote up
@Bean
public L3CacheStorageCustomizer l3CacheStorageCustomizer(){

    RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(hostName, port);
    config.setPassword(password);
    config.setDatabase(database);

    LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(config);
    connectionFactory.afterPropertiesSet();


    Jackson2JsonRedisSerializer<Object> jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer<Object>(
            Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    StringRedisTemplate stringRedisTemplate = new StringRedisTemplate();
    stringRedisTemplate.setConnectionFactory(connectionFactory);
    stringRedisTemplate.setValueSerializer(jackson2JsonRedisSerializer);
    stringRedisTemplate.setKeySerializer(new StringRedisSerializer());
    stringRedisTemplate.setHashKeySerializer(new StringRedisSerializer());

    stringRedisTemplate.afterPropertiesSet();

    return () -> {

        L3CacheStorage l3CacheStorage = new DefaultL3CacheStorage();
        ((DefaultL3CacheStorage) l3CacheStorage).setStringRedisTemplate(stringRedisTemplate);

        return l3CacheStorage;
    };
}
 
Example 8
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 9
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 10
Source File: RedisConfig.java    From ueboot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * spring boot 2.0后采用Lettuce作为redis调用客户端
 * 默认配置只支持单机模式,如需要其他模式,需要另外定义
 *
 * @return LettuceConnectionFactory
 */
@Bean
@ConditionalOnMissingBean(type = {"org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory"})
public LettuceConnectionFactory redisConnectionFactory(RedisProperties redisProperties) {
    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(redisProperties.getHost(),
            redisProperties.getPort());
    configuration.setDatabase(redisProperties.getDatabase());
    configuration.setPassword(RedisPassword.of(redisProperties.getPassword()));
    return new LettuceConnectionFactory(configuration);
}
 
Example 11
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 12
Source File: RedisConfig.java    From spring-boot-vue-admin with Apache License 2.0 5 votes vote down vote up
@Bean
@ConfigurationProperties(prefix = "spring.redis")
public RedisConnectionFactory redisConnectionFactory(
    @Qualifier(value = "jedisPoolConfig") final JedisPoolConfig jedisPoolConfig) {
  // 方法上的 @ConfigurationProperties 不生效
  // 未知 bug,暂时这样手动设置
  // fixme
  // 单机版 jedis
  final RedisStandaloneConfiguration redisStandaloneConfiguration =
      new RedisStandaloneConfiguration(
          this.redisProperties.getHost(), this.redisProperties.getPort());
  redisStandaloneConfiguration.setDatabase(this.redisProperties.getDatabase());
  redisStandaloneConfiguration.setPassword(this.redisProperties.getPassword());

  // 获得默认的连接池构造器
  final JedisClientConfiguration.JedisPoolingClientConfigurationBuilder jpcb =
      (JedisClientConfiguration.JedisPoolingClientConfigurationBuilder)
          JedisClientConfiguration.builder();
  // 指定 jedisPoolConifig 来修改默认的连接池构造器
  jpcb.poolConfig(jedisPoolConfig);
  // 连接超时
  jpcb.and().connectTimeout(Duration.ofSeconds(10));
  // 通过构造器来构造 jedis 客户端配置
  final JedisClientConfiguration jedisClientConfiguration = jpcb.build();
  // 单机配置 + 客户端配置 = jedis 连接工厂
  return new JedisConnectionFactory(redisStandaloneConfiguration, jedisClientConfiguration);
}
 
Example 13
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 14
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 15
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 16
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 17
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 18
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 19
Source File: RedisConfig.java    From spring-redis-websocket with Apache License 2.0 4 votes vote down vote up
@Bean
ReactiveRedisConnectionFactory reactiveRedisConnectionFactory(RedisProperties redisProperties) {
	RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(redisProperties.getHost(), redisProperties.getPort());
	redisStandaloneConfiguration.setPassword(redisProperties.getPassword());
	return new LettuceConnectionFactory(redisStandaloneConfiguration);
}