com.sinszm.sofa.ObjectRedisTemplate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of szm-sofa-boot-starter-jedis Show documentation
Show all versions of szm-sofa-boot-starter-jedis Show documentation
高可用服务框架,Jedis缓存操作组件 Copyright © 2021 智慧程序猿(sinsz.com) All rights reserved.
package com.sinszm.sofa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.context.annotation.Primary;
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;
import org.springframework.stereotype.Component;
/**
* Redis操作模板
*
* @author chenjianbo
*/
@Primary
@Component
@ConditionalOnClass({RedisAutoConfiguration.class, RedisTemplate.class})
public class ObjectRedisTemplate extends RedisTemplate {
@Autowired
public ObjectRedisTemplate(final RedisConnectionFactory redisConnectionFactory) {
RedisSerializer string = new StringRedisSerializer();
RedisSerializer object = new ObjectSerializer<>();
setEnableDefaultSerializer(true);
setDefaultSerializer(string);
setKeySerializer(string);
setValueSerializer(object);
setHashKeySerializer(string);
setHashValueSerializer(object);
setConnectionFactory(redisConnectionFactory);
afterPropertiesSet();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy