ZINCRBY command in redis

ZINCRBY key increment member

If the member already exists in the sorted set add the increment to its score and update the position of the element in the sorted set accordingly.

If a member does not already exist in the sorted set it is added with an increment as a score (that is, like if the previous score was virtually zero).

If the key does not exist a new sorted set with the specified member as a sole member is created.

If the key exists but does not hold a sorted set value an error is returned.

TIME COMPLEXITY: O(log(N)) with N being the number of elements in the sorted set

Note:

The score value can be the string representation of a double precision floating point number. It's possible to provide a negative value to perform a decrement.

RETURN VALUE: Integer reply, specifically:

The score of the member after the increment is performed.

Syntax:

ZINCRBY key increment member

Example 1: When the key is present.

redis:6379> ZADD key 10.9 member
(integer) 1
redis:6379> ZINCRBY key 98.7 member
"109.60000000000001"

Output

"109.60000000000001"


Example 2: When the key is not present.

redis:6379> ZINCRBY key1 98.7 member
"98.700000000000003"

Output

"98.700000000000003"


No comments:

Post a Comment