redis 设置成员更新的高效方式 [英] Efficient way redis set member update
问题描述
我有一个 redis 集.这个集合最多可以存储20个成员(添加SADD
命令).我的问题是;我需要在需要时更新这些成员.每个成员最多需要进行 10 次修改.集合成员是 json 作为字符串.我脑子里只有解决方案,也没有让所有成员更新并重新创建该集合.但这似乎很愚蠢.
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屋!