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

org.babyfish.jimmer.spring.cache.RedisCaches Maven / Gradle / Ivy

There is a newer version: 0.8.178
Show newest version
package org.babyfish.jimmer.spring.cache;

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.SerializationException;
import org.springframework.data.redis.serializer.StringRedisSerializer;

public class RedisCaches {

    private static final RedisSerializer NOP_SERIALIZER =
            new RedisSerializer() {
        @Override
        public byte[] serialize(byte[] t) throws SerializationException {
            return t;
        }
        @Override
        public byte[] deserialize(byte[] bytes) throws SerializationException {
            return bytes;
        }
    };

    private RedisCaches() {}

    public static RedisTemplate cacheRedisTemplate(
            RedisConnectionFactory connectionFactory
    ) {
        RedisTemplate template = new RedisTemplate<>();
        template.setConnectionFactory(connectionFactory);
        template.setKeySerializer(StringRedisSerializer.UTF_8);
        template.setValueSerializer(NOP_SERIALIZER);
        template.setHashKeySerializer(StringRedisSerializer.UTF_8);
        template.setHashValueSerializer(NOP_SERIALIZER);
        template.afterPropertiesSet();
        return template;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy