Spring註解方式配置Redis
阿新 • • 發佈:2018-11-09
@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; } }
基本的配置是這樣的。