| | |
| | | @EnableCaching |
| | | @Slf4j |
| | | public class RedisConfig extends CachingConfigurerSupport { |
| | | |
| | | @Bean |
| | | @SuppressWarnings(value = {"unchecked", "rawtypes"}) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { |
| | | RedisTemplate<Object, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(connectionFactory); |
| | | |
| | | FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); |
| | | |
| | | // 使用StringRedisSerializer来序列化和反序列化redis的key值 |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setValueSerializer(serializer); |
| | | |
| | | // Hash的key也采用StringRedisSerializer的序列化方式 |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | @Bean |
| | | public JedisPoolConfig jedisPoolConfig() { |
| | | JedisPoolConfig config = new JedisPoolConfig(); |
| | | // 设置JedisPoolConfig的相关参数,例如最大连接数、最大空闲时间等 |
| | | config.setMinIdle(0); |
| | | config.setMaxIdle(8); |
| | | config.setMaxTotal(8); |
| | | config.setMaxWaitMillis(-1); |
| | | config.setTestOnBorrow(true); |
| | | config.setTestOnReturn(true); |
| | | // config.setMinIdle(0); |
| | | // config.setMaxIdle(8); |
| | | // config.setMaxTotal(8); |
| | | // config.setMaxWaitMillis(-1); |
| | | // config.setTestOnBorrow(true); |
| | | // config.setTestOnReturn(true); |
| | | return config; |
| | | } |
| | | @Bean |
| | |
| | | } |
| | | return factory; |
| | | } |
| | | @Bean |
| | | @SuppressWarnings(value = {"unchecked", "rawtypes"}) |
| | | public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) { |
| | | RedisTemplate<Object, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(connectionFactory); |
| | | |
| | | FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class); |
| | | |
| | | // 使用StringRedisSerializer来序列化和反序列化redis的key值 |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setValueSerializer(serializer); |
| | | |
| | | // Hash的key也采用StringRedisSerializer的序列化方式 |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | |
| | | template.afterPropertiesSet(); |
| | | return template; |
| | | } |
| | | |
| | | @Bean |
| | | public DefaultRedisScript<Long> limitScript() { |