spring - 使用 Redis 作为 Spring 缓存管理器以缓存自定义 Java 对象

标签 spring caching redis

我想使用 Redis 作为缓存管理器,以便缓存来自 MySQL 数据库的 JPA 实体

我是 Redis 的新手,Redis 似乎只能缓存它知道的基本类型/结构(字符串、哈希等)

我的问题是:我可以使用 Redis(连同 Spring 缓存抽象)作为 spring 缓存管理器来缓存我的自定义对象(比如 Person订单客户等...)?

最佳答案

您可以先查看 Spring Data Redis ,但与 Spring Data JPA 不同,它不提供存储库抽象,而是使用 Spring 模板和仅特定于 redis 的访问器方法。由于 Redis 不支持关系,因此您必须通过覆盖 JPA 的标准 CRUD 操作来设计和实现这些关系。

这是一篇很棒的文章,详细介绍了您喜欢的东西...
http://www.packtpub.com/article/building-applications-spring-data-redis

I am new to Redis and it seems Redis is only able to cache the basic types/structures it knows (strings, hashes, etc.)

Redis 可以存储任何东西;文本、json、二进制数据,都无所谓。

默认情况下,RedisTemplate (Spring Data Redis 的一部分),使用 Java 序列化将对象编码/解码到/从 Redis,但与 MessagePack 之类的东西相比,它在 Redis 中使用了更多空间。 ,基于我的测试。

关于spring - 使用 Redis 作为 Spring 缓存管理器以缓存自定义 Java 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18055635/

相关文章:

java - Spring Boot |使用动态 keystore /信任库

java - spring-kafka 中未应用最小获取字节数属性

json - Wordpress Json API 缓存

java - EclipseLink 中的@Cache

redis - 在 Redis-sentinel 主从配置中,新主控显示为初始主控关闭

node.js - Redis 集群 : will hgetall search all nodes in cluster for key?

java - Intellij Spring 和 Tomcat 部署

java - JPA : Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1 上的问题

php - Silverstripe TinyMCE 在负载均衡器后面崩溃。

java - 使用来自依赖 jar 的 Spring CacheManager