我希望使用Redis作为缓存管理器,以便从MySQL数据库中获取缓存JPA实体。
我对Redis很陌生,似乎Redis是只能够缓存它所知道的基本类型/结构(字符串、散列等)。
我的问题是:我是否可以使用Redis (连同Spring缓存抽象)作为一个spring缓存管理器来缓存我的自定义对象(例如Person
、Order
、Customer
等)?
发布于 2013-08-05 16:07:48
您可以从查看春季数据红宝石开始,但是与Spring不同的是,is并不提供存储库抽象,而是使用只针对redis的访问器方法的Spring模板。因为Redis不支持关系,所以您必须通过重写JPA的标准CRUD操作来设计和实现这些关系。
这是一篇很棒的文章,详细介绍了一些你喜欢的东西.
http://www.packtpub.com/article/building-applications-spring-data-redis
我对Redis很陌生,似乎Redis只能缓存它所知道的基本类型/结构(字符串、散列等)。
Redis可以存储任何东西;文本、json、二进制数据,都不重要。
默认情况下,RedisTemplate ( Spring的一部分)使用JAVA序列化来封送/发送redis对象,但根据我的测试,它在redis中使用的空间比类似MessagePack的空间要大。
发布于 2016-02-10 12:17:00
雷迪森提供了基于Redis的Spring提供程序。它支持诸如ttl
和maxIdleTime
这样的重要缓存设置用于Redis存储,并支持许多流行的编解码器:Jackson JSON
、Avro
、Smile
、CBOR
、MsgPack
、Kryo
、FST
、LZ4
、Snappy
和JDK Serialization
。
配置示例如下:
@Configuration
@ComponentScan
@EnableCaching
public static class Application {
@Bean(destroyMethod="shutdown")
RedissonClient redisson() {
Config config = ...
return Redisson.create(config);
}
@Bean
CacheManager cacheManager(RedissonClient redissonClient) throws IOException {
Map<String, CacheConfig> config = new HashMap<String, CacheConfig>();
// ttl = 24 mins, maxIdleTime = 12 mins
config.put("testCache", new CacheConfig(24*60*1000, 12*60*1000));
return new RedissonSpringCacheManager(redissonClient, config);
}
}
https://stackoverflow.com/questions/18055635
复制相似问题