Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Incr command

Redis Incr command

Redis string

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

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

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

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

Syntax

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



redis 127.0.0.1:6379> INCR KEY_NAME 

Available Version

= 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