redisson getbucket set 值有前缀

问题

在使用redisson存储数据时,发现redis存储的值会有一串前缀。

解决方案

找了一圈发现是因为redisson默认使用的Jackson JSON做的数据序列化,可以使用StringCodec作为序列化工具。更多序列化工具可以从redisson的包中查找,具体包路径为org.redisson.codecorg.redisson.client.codec。作如下更改:

//1.全局配置
@Bean
public RedissonClient redissonClient() {
    Config config = new Config();
    // 一些其他配置
    // ...
    config.setCodec(new StringCodec(StandardCharsets.UTF_8));
    return Redisson.create(config);
}

//2.使用时配置
RBucket<String> xxx = redissonClient.getBucket(key, new StringCodec(StandardCharsets.UTF_8));
xxx.set(string)
xxx.get()
posted @ 2022-05-26 15:29  豌里个豆  阅读(1330)  评论(0编辑  收藏  举报