Hi, I'm using OCI redis on cloud, but jedisConnectionFactory returns the error org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection. Why? thanks
Hi Sorry I have no time for debugging. You can have a look to the OCI doc or may be my code there will show you something : package com.example.redis; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.jedis.JedisClientConfiguration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; @Configuration @ComponentScan("com.example.redis") @EnableRedisRepositories(basePackages = "com.example.redis") @PropertySource("classpath:application.properties") public class RedisConfig { @Bean JedisConnectionFactory jedisConnectionFactory() { RedisStandaloneConfiguration redisStandaloneConfiguration = null; JedisClientConfiguration jedisConfig = null; JedisConnectionFactory jedisConnectionFactory = null;
//Local Redis if (Environment._PROFILE.equals("REDIS")) { redisStandaloneConfiguration = new RedisStandaloneConfiguration(Environment._ENDPOINT, Integer.parseInt(Environment._PORT)); redisStandaloneConfiguration.setPassword(Environment._PASSWORD); jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration); } //OCI Env else { redisStandaloneConfiguration = new RedisStandaloneConfiguration(Environment._ENDPOINT, Integer.parseInt(Environment._PORT)); jedisConfig = JedisClientConfiguration .builder() .useSsl() .build(); jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, jedisConfig); } return jedisConnectionFactory; } }
Hi, I'm using OCI redis on cloud, but jedisConnectionFactory returns the error org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection. Why? thanks
Hi Sorry I have no time for debugging. You can have a look to the OCI doc or may be my code there will show you something : package com.example.redis;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisClientConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
@Configuration
@ComponentScan("com.example.redis")
@EnableRedisRepositories(basePackages = "com.example.redis")
@PropertySource("classpath:application.properties")
public class RedisConfig {
@Bean
JedisConnectionFactory jedisConnectionFactory() {
RedisStandaloneConfiguration redisStandaloneConfiguration = null;
JedisClientConfiguration jedisConfig = null;
JedisConnectionFactory jedisConnectionFactory = null;
//Local Redis
if (Environment._PROFILE.equals("REDIS")) {
redisStandaloneConfiguration = new RedisStandaloneConfiguration(Environment._ENDPOINT, Integer.parseInt(Environment._PORT));
redisStandaloneConfiguration.setPassword(Environment._PASSWORD);
jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration);
}
//OCI Env
else {
redisStandaloneConfiguration = new RedisStandaloneConfiguration(Environment._ENDPOINT, Integer.parseInt(Environment._PORT));
jedisConfig = JedisClientConfiguration
.builder()
.useSsl()
.build();
jedisConnectionFactory = new JedisConnectionFactory(redisStandaloneConfiguration, jedisConfig);
}
return jedisConnectionFactory;
}
}
@@christophepruvost44 thanks, for quickly reply. The error occured when use opsForValues().get
RedisTemplate template = new RedisTemplate();
System.out.println( "=>>>0");
template.setConnectionFactory(jedisConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new JdkSerializationRedisSerializer());
template.setValueSerializer(new JdkSerializationRedisSerializer());
template.setEnableTransactionSupport(true);
template.afterPropertiesSet();
System.out.println( "=>>>1");
Object valobj = template.opsForValue().get("TEST");