Redis - 有序集 Zincrby 命令



Redis ZINCRBY 命令按增量增加键中存储的有序集中的成员评分。如果成员在有序集中不存在,则将其添加,其评分为增量(如同其之前的评分为 0.0)。如果键不存在,则创建一个新的有序集,其指定成员为其唯一的成员。当键存在但不是有序集时,将返回错误。

返回值

字符串响应,成员的新评分(双精度浮点数),表示为字符串。

语法

以下是 Redis ZINCRBY 命令的基本语法。

redis 127.0.0.1:6379> ZINCRBY KEY INCREMENT MEMBER

示例

redis 127.0.0.1:6379> ZADD myset 1 "hello" 
(integer) 1 
redis 127.0.0.1:6379> ZADD myset 1 "foo" 
(integer) 1 
redis 127.0.0.1:6379> ZINCRBY myzset 2 "hello" 
(integer) 3 
redis 127.0.0.1:6379> ZRANGE myzset 0 -1 WITHSCORES 
1) "foo" 
2) "2" 
3) "hello" 
4) "3"
redis_sorted_sets.htm
广告
© . All rights reserved.