I have Spring Redis working using spring-data-redis with all default configuration likes localhost default port and so on.
Now
This works for me :
@Configuration
@EnableRedisRepositories
public class RedisConfig {
@Bean
public JedisConnectionFactory jedisConnectionFactory() {
RedisProperties properties = redisProperties();
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
configuration.setHostName(properties.getHost());
configuration.setPort(properties.getPort());
return new JedisConnectionFactory(configuration);
}
@Bean
public RedisTemplate redisTemplate() {
final RedisTemplate template = new RedisTemplate<>();
template.setConnectionFactory(jedisConnectionFactory());
template.setValueSerializer(new GenericToStringSerializer<>(Object.class));
return template;
}
@Bean
@Primary
public RedisProperties redisProperties() {
return new RedisProperties();
}
}
and properties file :
spring.redis.host=localhost
spring.redis.port=6379