位置:首页 » 文章/教程分享 » 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"