在REDIS中增加中等大小排序集的最佳方法是什么?(最好使用java驱动程序JEDIS)Set中有大约100-200K条记录.我想用给定的双数增加他们的分数.
1 a
2 b
3 c
Run Code Online (Sandbox Code Playgroud)
2 a
3 b
4 c
Run Code Online (Sandbox Code Playgroud)
我想出的唯一可能的解决方案是:
还有其他/更好的方法吗?
以下是如何在REDIS中使用EVAL和Lua来执行for循环以递增所有已排序的集合成员.
local members = redis.call('zrange',KEYS[1],0,-1)
for i, member in ipairs(members) do
redis.call('zincrby',KEYS[1],inc,member)
end
Run Code Online (Sandbox Code Playgroud)
将其保存为字符串并使用您的驱动程序运行eval(在本例中为java).执行没有返回.
使用Jedis
// script is the script string
// 1 is the number of keys- keep it this way for this script
// myzset is the name of your sorted set
// 1.5 is the increment, you can use +/- values to inc/dec.
jedis.eval(script, …
Run Code Online (Sandbox Code Playgroud)