新增:redis工具类重构,配置主从,哨兵模式。hpc大文件上传优化。
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
package com.sdm.data.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
@Bean(name = "redisTemplate")
|
||||
public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||
RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
||||
|
||||
template.setConnectionFactory(factory);
|
||||
// key序列化方式
|
||||
template.setKeySerializer(redisSerializer);
|
||||
// value序列化
|
||||
template.setValueSerializer(redisSerializer);
|
||||
// value hashmap序列化
|
||||
template.setHashValueSerializer(redisSerializer);
|
||||
// key haspmap序列化
|
||||
template.setHashKeySerializer(redisSerializer);
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
@Bean(name = "bytesRedisTemplate")
|
||||
public RedisTemplate<String, byte[]> bytesRedisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
RedisTemplate<String, byte[]> redisTemplate = new RedisTemplate<>();
|
||||
redisTemplate.setConnectionFactory(connectionFactory);
|
||||
// 设置key和value的序列化规则
|
||||
redisTemplate.setValueSerializer(RedisSerializer.byteArray());
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.afterPropertiesSet();
|
||||
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//package com.sdm.data.config;
|
||||
//
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
//import org.springframework.data.redis.core.RedisTemplate;
|
||||
//import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
//import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
//
|
||||
//@Configuration
|
||||
//public class RedisConfig {
|
||||
//
|
||||
// @Bean(name = "redisTemplate")
|
||||
// public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory factory) {
|
||||
// RedisTemplate<Object, Object> template = new RedisTemplate<>();
|
||||
// RedisSerializer<String> redisSerializer = new StringRedisSerializer();
|
||||
//
|
||||
// template.setConnectionFactory(factory);
|
||||
// // key序列化方式
|
||||
// template.setKeySerializer(redisSerializer);
|
||||
// // value序列化
|
||||
// template.setValueSerializer(redisSerializer);
|
||||
// // value hashmap序列化
|
||||
// template.setHashValueSerializer(redisSerializer);
|
||||
// // key haspmap序列化
|
||||
// template.setHashKeySerializer(redisSerializer);
|
||||
//
|
||||
// return template;
|
||||
// }
|
||||
//
|
||||
// @Bean(name = "bytesRedisTemplate")
|
||||
// public RedisTemplate<String, byte[]> bytesRedisTemplate(RedisConnectionFactory connectionFactory) {
|
||||
// RedisTemplate<String, byte[]> redisTemplate = new RedisTemplate<>();
|
||||
// redisTemplate.setConnectionFactory(connectionFactory);
|
||||
// // 设置key和value的序列化规则
|
||||
// redisTemplate.setValueSerializer(RedisSerializer.byteArray());
|
||||
// redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// redisTemplate.afterPropertiesSet();
|
||||
//
|
||||
// return redisTemplate;
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user