@
yueyoum redis 127.0.0.1:6379> ZADD rank 1 a
(integer) 1
redis 127.0.0.1:6379> ZADD rank 2 b
(integer) 1
redis 127.0.0.1:6379> ZADD rank 3 c
(integer) 1
redis 127.0.0.1:6379> ZADD rank 4 d
(integer) 1
redis 127.0.0.1:6379> ZADD rank 5 e
(integer) 1
redis 127.0.0.1:6379> ZRANGE rank 0 -1
1) "a"
2) "b"
3) "c"
4) "d"
5) "e"
redis 127.0.0.1:6379> ZSCORE rank e
"5"
redis 127.0.0.1:6379> ZSCORE rank b
"2"
redis 127.0.0.1:6379> ZADD rank 2 e
(integer) 0
redis 127.0.0.1:6379> ZADD rank 5 b
(integer) 0
redis 127.0.0.1:6379> ZRANGE rank 0 -1
1) "a"
2) "e"
3) "c"
4) "d"
5) "b"
因为你是用 eval,能保证事务性,我就不写 watch 的代码了。