Communicating between the client and redis may take a lot of time. To avoid that, you can take a "SET-type" copy of the sorted set. For instance, say you have a sorted set "key1":
1 a
2 b
3 c
And you have a set "key2":
a, b, c
Than you can implement the increment easily:
def increase_sorted_set(increment = 1)
redis.ZINTERSTORE("key1", 2, "key1", "key2", "WEIGHTS", "1", increment)
end
Redis will give each member of the (non-sorted) set key2
a default score of 1
.
For example:
redis 127.0.0.1:6379> ZADD key1 1 a 2 b 3 c
(integer) 3
redis 127.0.0.1:6379> SADD key2 a b c
(integer) 3
redis 127.0.0.1:6379> ZINTERSTORE key1 2 key1 key2 WEIGHTS 1 7
(integer) 3
redis 127.0.0.1:6379> ZRANGE key1 0 -1 WITHSCORES
1) "a"
2) "8"
3) "b"
4) "9"
5) "c"
6) "10"