Easy Tutorial
❮ Pub Sub Punsubscribe Sorted Sets Zincrby ❯

Redis Incrby Command

Redis Strings

The Redis Incrby command increments the number stored at the key by a specified increment value.

If the key does not exist, the key's value is initialized to 0 before the INCRBY command is executed.

If the value contains the wrong type, or if the string value cannot be represented as a number, an error is returned.

The value of this operation is limited to a 64-bit signed number.

Syntax

The basic syntax of the redis Incrby command is as follows:

redis 127.0.0.1:6379> INCRBY KEY_NAME INCR_AMOUNT

Available Versions

= 1.0.0

Return Value

The value of the key after the increment.

Examples

# Key exists and is a numeric value

redis> SET rank 50
OK

redis> INCRBY rank 20
(integer) 70

redis> GET rank
"70"


# Key does not exist

redis> EXISTS counter
(integer) 0

redis> INCRBY counter 30
(integer) 30

redis> GET counter
"30"


# Key is not a numeric value

redis> SET book "long long ago..."
OK

redis> INCRBY book 200
(error) ERR value is not an integer or out of range

Redis Strings

❮ Pub Sub Punsubscribe Sorted Sets Zincrby ❯