Home > Backend Development > PHP Problem > What is the usage of incr in php connection to redis

What is the usage of incr in php connection to redis

WBOY
Release: 2023-03-15 10:26:02
Original
3908 people have browsed it

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".

What is the usage of incr in php connection to redis

The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

What is the usage of incr in php connection to redis

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
Copy after login

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"
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template