Redis命令-有序集合-zincrby

原文

http://redis.io/commands/zincrby

简介

Increment the score of a member in a sorted set.

增加有序集合中一个成员的分数。

语法

ZINCRBY key increment member

版本

Available since 1.2.0.

自1.2.0版本可用。

时间复杂度

Time complexity: O(log(N)) where N is the number of elements in the sorted set.

O(log(N)):N是有序集合中元素的数量。

描述

Increments the score of member in the sorted set stored at key by increment. If member does not exist in the sorted set, it is added with increment as its score (as if its previous score was 0.0). If key does not exist, a new sorted set with the specified member as its sole member is created.

把有序集合中指定成员member的分数增加increment。如果有序集合中不存在该成员,这个成员会被添加到有序集合中,并把increment作为它的分数。如果key不存在,一个新的有序集合被创建,指定的成员作为新有序集合的唯一成员。

An error is returned when key exists but does not hold a sorted set.

当key存在但不是有序集合时,返回错误。

The score value should be the string representation of a numeric value, and accepts double precision floating point numbers. It is possible to provide a negative value to decrement the score.

分数值score应该是数字值的字符串表示,可以接受双精度浮点数。可以提供负值来减少分数。

返回值

Bulk string reply: the new score of member (a double precision floating point number), represented as string.

Bulk string:以字符串形式表示的成员的新分数(双精度浮点数)。

例子

redis>  ZADD myzset 1 "one"
(integer) 1
redis>  ZADD myzset 2 "two"
(integer) 1
redis>  ZINCRBY myzset 2 "one"
"3"
redis>  ZRANGE myzset 0 -1 WITHSCORES
1) "two"
2) "2"
3) "one"
4) "3"
redis>

猜你喜欢

转载自gitzhangyl.iteye.com/blog/2289484