使用 spring-data-redis 更新 redis 中的实体 [英] Update entity in redis with spring-data-redis

查看:66
本文介绍了使用 spring-data-redis 更新 redis 中的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 Redis (3.2.100) 和 Spring data redis (1.8.9) 以及 Jedis 连接器.当我对现有实体使用 save() 函数时,Redis 会删除我的实体并重新创建该实体.

I'm currently using Redis (3.2.100) with Spring data redis (1.8.9) and with Jedis connector. When i use save() function on an existing entity, Redis delete my entity and re create the entity.

在我的例子中,我需要保留这个现有的实体并且只更新实体的属性.(我有另一个线程同时读取同一个实体)

In my case i need to keep this existing entity and only update attributes of the entity. (I have another thread which read the same entity at the same time)

在 Spring 文档中(https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.repositories.partial-updates),我找到了部分更新功能.不幸的是,文档中的示例使用了 RedisTemplate 的 update() 方法.但是这种方法不存在.

In Spring documentation (https://docs.spring.io/spring-data/data-redis/docs/current/reference/html/#redis.repositories.partial-updates), i found the partial update feature. Unfortunately, the example in the documentation use the update() method of RedisTemplate. But this method do not exist.

那你用过 Spring-data-redis 部分更新吗?

So did you ever use Spring-data-redis partial update?

之前没有delete也有更新实体redis的方法吗?

There is another method to update entity redis without delete before?

谢谢

推荐答案

要获得RedisKeyValueTemplate,你可以:

@Autowired
private RedisKeyValueTemplate redisKVTemplate;

redisKVTemplate.update(entity)

redisKVTemplate.update(entity)

这篇关于使用 spring-data-redis 更新 redis 中的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆