Home > Article > Backend Development > What is the usage of incr in php connection to redis
In PHP, the Incr command of redis is used to increment the numerical value stored in the key. If the key does not exist, the value of the key will first be initialized to 0 and then the Incr operation will be performed. The result returned It is the value of key after executing the Incr command, and the syntax is "INCR KEY_NAME".
The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer
The Redis Incr command increments the numeric value stored in the key by one.
If key does not exist, the value of key will be initialized to 0 first, and then the INCR operation will be performed.
If the value contains the wrong type, or a string type value cannot be represented as a number, then an error is returned.
The value of this operation is limited to 64-bit (bit) signed digital representation.
Syntax
The basic syntax of the redis Incr command is as follows:
redis 127.0.0.1:6379> INCR KEY_NAME
Return value
The value of key after executing the INCR command.
Examples are as follows:
redis> SET page_view 20 OK redis> INCR page_view (integer) 21 redis> GET page_view # 数字值在 Redis 中以字符串的形式保存 "21"
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the usage of incr in php connection to redis. For more information, please follow other related articles on the PHP Chinese website!