Latest web development tutorials

Redis Incrby command

Redis string (string)

Redis Incrby command key stored in digital plus incremental value specified.

If the key is not present, then the value of the key will first be initialized to 0, and then execute INCRBY command.

If the value type or string type containing the error can not be expressed as a number, it returns an error.

This operation is limited to the value of 64-bit (bit) signed within the digital representation.

grammar

redis Incrby basic command syntax is as follows:

redis 127.0.0.1:6379> INCRBY KEY_NAME INCR_AMOUNT

Available versions

> = 1.0.0

return value

Plus the increment value specified after, key value.

Examples

# key 存在且是数字值

redis> SET rank 50
OK

redis> INCRBY rank 20
(integer) 70

redis> GET rank
"70"


# key 不存在时

redis> EXISTS counter
(integer) 0

redis> INCRBY counter 30
(integer) 30

redis> GET counter
"30"


# key 不是数字值时

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

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

Redis string (string)