Spring Data Redis(Repositories-Persisting References)
来源:互联网 发布:为什么30岁不能学java 编辑:程序博客网 时间:2024/06/02 07:56
Persisting References
给属性添加@Reference 注解后,会存储一个简单的key 引用而不是拷贝所有的值到hash 中。从Redis 中读取时,引用会被自动的处理,映射回到对象中。
Example 17. Sample Property Reference
_class = org.example.Personid = e2c7dcee-b8cd-4424-883e-736ce564363efirstname = randlastname = al’thormother = persons:a9d4b3a0-50d3-4538-a2fc-f7fc2581ee56
Reference 存储了被引用对象的整个key (keyspace:id) 。
被引用的对象不受限制于引用对象的持续变化。请确保对引用对象的持续变更是独立的,因为只有引用被存储了。在引用类型的属性上设置的索引将不会被处理。
Persisting Partial Updates
有时候,仅仅为了设置一个新的值,而加载或重写整个实体是没必要的。当你仅仅想修改一个属性时,为它设置一个最后活跃的会话时间戳是个不错的方案。在已经存在的对象上,当你关注于更新整个实体的潜在过期时间,以及索引结构时,PartialUpdate 允许你定义set 和delete 事件。
Example 18. Sample Partial UpdatePartialUpdate<Person> update = new PartialUpdate<Person>("e2c7dcee", Person.class) .set("firstname", "mat") .set("address.city", "emond's field") .del("age"); template.update(update);update = new PartialUpdate<Person>("e2c7dcee", Person.class) .set("address", new Address("caemlyn", "andor")) .set("attributes", singletonMap("eye-color", "grey")); template.update(update);update = new PartialUpdate<Person>("e2c7dcee", Person.class) .refreshTtl(true); .set("expiration", 1000);template.update(update);
Set the simple property firstname to mat.Set the simple property address.city to emond’s field without having to pass in the entire object. This does not work when a custom conversion is registered.Remove the property age.Set complex property address.Set a map/collection of values removes the previously existing map/collection and replaces the values with the given ones.Automatically update the server expiration time when altering Time To Live.
更新复杂的对象或 map/collection 结构,需要和Redis 做进一步的交互来确认值是否存在,这意味着重写整个实体会更快一些。
阅读全文
0 0
- Spring Data Redis(Repositories-Persisting References)
- Spring Data Redis(Redis Repositories)
- Spring Data Redis(Repositories-Keyspaces)
- Spring Data Redis(Repositories-Secondary Indexes)
- Spring Data Redis(Repositories-Time To Live)
- Spring Data Redis(Repositories-CDI integration)
- Spring Data Redis(Redis Repositories running on Cluster)
- Spring Data Redis(Repositories-Object to Hash Mapping)
- Spring Data Redis(Repositories-Queries and Query Methods)
- Spring Data Repositories 使用记录
- Spring Data repositories with multiple databases
- Spring Data JPA repositories using JavaConfig
- redis:spring-data-redis
- Redis references
- redis Jredis spring-data-redis
- spring data redis 操作redis
- Spring Data Redis (Redis Support)
- Spring Data Redis(Redis Transactions)
- Anniversary Cake POJ
- 在豌豆荚安卓市场下载了伪造的ES文件管理器,该流氓apk会自动的下载手机游戏
- 处理器字长
- 线程池的原理及实现(2)
- C++11 std::bind std::function 高级用法
- Spring Data Redis(Repositories-Persisting References)
- 使用Eclipse编写第一个Hibernate程序
- 有一个大数组,var a = ['1', '2', '3', ...];a的长度是100,内容填充随机整数的字符串.请先构造此数组a,然后设计一个算法将其内容去重
- Linux系统su命令的详细用法
- Android 快速开发之 Live Templates
- 如何在mysql下实现事务的提交与回滚
- 三目运算进行赋值
- 389. Find the Difference
- 回首第一份工作