Springboot-Redisson - 3.数据序列化
在Spring Boot项目中使用Redisson进行数据序列化,你需要配置一个自定义的RedissonClient
实例。以下是一个配置示例,使用了Jackson2JsonRedissonSerializer作为序列化方式:
import com.fasterxml.jackson.databind.ObjectMapper;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.jackson.Jackson2JsonRedissonSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RedissonConfig {
@Bean(destroyMethod="shutdown")
public RedissonClient redisson() {
Config config = new Config();
// 使用单节点配置
config.useSingleServer()
.setAddress("redis://127.0.0.1:6379");
// 创建Jackson2JsonRedissonSerializer
ObjectMapper mapper = new ObjectMapper();
Jackson2JsonRedissonSerializer<Object> jackson2JsonRedissonSerializer = new Jackson2JsonRedissonSerializer<>(mapper);
评论已关闭