高效的方式redis设置成员更新 [英] Efficient way redis set member update
问题描述
我有一套redis。此集最多可存储20个成员(使用 SADD
命令添加)。
我的问题是;我需要在需要时更新这些成员。会员每个会员最多需要修改10次。设置成员是json作为字符串。我脑子里只有solutoin,也让所有成员更新并重新创建该组。但它似乎很独特。
I have a redis set. This set can store 20 members maximum(added withSADD
command).
My problem is ; I need to update that members when needed. Members need that modification maximum 10 times for every member. Set members are json as a string. There is only solutoin on my mind nor, get all members update and recreate that set again. But it seems iditoic.
我知道有 ZADD
排序集及其得分支持它似乎也适合我也需要更新json中的数据得分,但我只是想知道是否有任何方法以有效的方式更新成员,或者更新成员在redis方式上不可接受?
I know there is ZADD
sorted set with its score support it seems suitable also I need to update score like data in json , but i just wonder Is there any method updating members in efficient way, or is updating member not acceptable on redis way ?
注意:redis数据存储区正由node.js和java客户端使用。
推荐答案
设置成员本身是不可变的 - 您可以添加新成员或删除现有成员。就是这样。
Set members themselves are immutable - you can add new members or remove existing ones. That's it.
鉴于一个集合是一个无序的独特成员集合,考虑可能的结果是成员在理论上可以修改成员的新值:
Given that a set is an unordered collection of unique members, consider the possible outcomes were set members theoretically modifiable when the new value for a member:
- 与旧值相同 - 集合中没有更改
- 已存在于集合中 - 相当于删除该成员
- 不是1或2 - 相当于删除该成员并添加一个新成员
这篇关于高效的方式redis设置成员更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!