yml文件配置
spring:data:redis:host: 47.97.32.27port: 57842password: 123456lettuce:pool:max-active: 8 max-idle: 8 min-idle: 0 max-wait: 3000 timeout: 10000
RedisConfig
package com.nnutc.system.config;
@Configuration
public class RedisConfig {@Bean
@SuppressWarnings(value = {"unchecked", "rawtypes"})public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<Object, Object> template = new RedisTemplate<>();template.setConnectionFactory(connectionFactory);template.setKeySerializer(new StringRedisSerializer());template.setValueSerializer(new FastJsonRedisSerializer<>(Object.class));template.setHashKeySerializer(new StringRedisSerializer());template.setHashValueSerializer(new FastJsonRedisSerializer<>(Object.class));return template; }
}