Redis Incr Command

Redis String (string)

The Redis Incr command increments the numeric value stored in key by one.

If the key does not exist, the value of the key is first initialized to 0, and then the INCR operation is performed.

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

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

Syntax

The basic syntax of the Redis Incr command is as follows:

redis 127.0.0.1:6379> INCR KEY_NAME 

Available Versions

>= 1.0.0

Return Value

The value of key after executing the INCR command.

Example

redis> SET page_view 20
OK

redis> INCR page_view
(integer) 21

redis> GET page_view    # 数字值在 Redis 中以字符串的形式保存
"21"

Redis String (string)

Other Extensions