Giter Site home page Giter Site logo

[FEATURE]利用Spring缓存注解如@Cacheable操作redis,后台查看redis中的数据,value是乱码,建议序列化为 json about spring-boot-demo HOT 2 CLOSED

xkcoding avatar xkcoding commented on May 2, 2024
[FEATURE]利用Spring缓存注解如@Cacheable操作redis,后台查看redis中的数据,value是乱码,建议序列化为 json

from spring-boot-demo.

Comments (2)

meetshawn avatar meetshawn commented on May 2, 2024

我只是有遇到过,序列化的问题,程序取没有问题,但是给其他程序用也是乱码,自己加个序列化就可以了

from spring-boot-demo.

xkcoding avatar xkcoding commented on May 2, 2024

@RhymeXY 这个默认是以序列化的形式存入 Redis 的,如果你想要去 Redis 检查数据的话,可以参考我新提交的代码,将数据序列化为 json 格式,但是需要注意的是,生产环境不要随意切换序列化的方式哦,会因为序列化方式不一致,导致反序列化失败的情况。

/**
* 配置使用注解的时候缓存配置,默认是序列化反序列化的形式,加上此配置则为 json 形式
*/
@Bean
public CacheManager cacheManager(RedisConnectionFactory factory) {
// 配置序列化
RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
RedisCacheConfiguration redisCacheConfiguration = config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer())).serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer()));
return RedisCacheManager.builder(factory).cacheDefaults(redisCacheConfiguration).build();
}

from spring-boot-demo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.