@Configuration public class RedisConfig { @Value("${spring.data.redis.host}") private String redisHost; @Value("${spring.data.redis.port}") private int redisPort; @Bean(name = "jedisConnectionFactory") JedisConnectionFactory jedisConnectionFactory() { RedisStandaloneConfiguration rsc = new RedisStandaloneConfiguration(); rsc.setHostName(redisHost); rsc.setPort(redisPort); return new JedisConnectionFactory(rsc); } @Bean(name = "redisTemplate") public RedisTemplate<String, String> redis0Template() { RedisTemplate<String, String> template = new RedisTemplate<>(); template.setConnectionFactory(jedisConnectionFactory()); RedisSerializer<String> stringSerializer = new StringRedisSerializer(); template.setKeySerializer(stringSerializer); template.setValueSerializer(stringSerializer); template.setHashKeySerializer(stringSerializer); template.setHashValueSerializer(stringSerializer); return template; } }
spring: data: redis: host: 127.0.0.1 port: 6380
标签:Springboot,stringSerializer,spring,配置,redis,rsc,template,new From: https://www.cnblogs.com/namedlxd/p/18408217