redis zset score 求和

redis zset score 求和
`local sum=0
local z=redis.call(‘ZRANGE’, KEYS[1], 0, -1, ‘WITHSCORES’)

for i=2, #z, 2 do
sum=sum+z[i]
end

return sum`

例子:

```lua
~$ redis-cli zadd z 1 a 2 b 3 c 4 d 5 e
(integer) 5
~$ redis-cli eval "local sum=0 local z=redis.call('ZRANGE', KEYS[1], 0, -1, 'WITHSCORES') for i=2, #z, 2 do sum=sum+z[i] end return sum" 1 z
(integer) 15

源自

你可能感兴趣的:(redis)