All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sinszm.sofa.ObjectRedisTemplate Maven / Gradle / Ivy

Go to download

高可用服务框架,Jedis缓存操作组件 Copyright © 2021 智慧程序猿(sinsz.com) All rights reserved.

There is a newer version: 1.3.6
Show newest version
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