1. 程式人生 > >Spring註解方式配置Redis

Spring註解方式配置Redis

@Configuration
public class RedisConfiguraion {

    @Bean
    public JedisConnectionFactory redisConnectionFactory() {
        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
        configuration.setHostName("ip地址");
        configuration.setPort(6379);
        //configuration.setPassword(RedisPassword.of("123456"));
return new JedisConnectionFactory(configuration); } @Bean public RedisTemplate redisTemplate(JedisConnectionFactory factory){ RedisTemplate redisTemplate = new RedisTemplate(); redisTemplate.setConnectionFactory(factory); return redisTemplate; } }

基本的配置是這樣的。