org.babyfish.jimmer.spring.cache.RedisCaches Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jimmer-spring-boot-starter Show documentation
Show all versions of jimmer-spring-boot-starter Show documentation
A revolutionary ORM framework for both java and kotlin
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;
}
}