Home > Database > Redis > body text

What is the general redis cache time?

anonymity
Release: 2019-06-05 09:34:45
Original
10996 people have browsed it

redis expiration time

Introduction to redis expiration time Sometimes we don’t want the redis key to always exist. For example, cache, verification code and other data, we hope that they can be automatically destroyed within a certain period of time. Redis provides some commands that allow us to set the expiration time for the key and let the key be automatically deleted after it expires.

What is the general redis cache time?

redis expiration time related commands

1.EXPIRE PEXPIREEXPIRE interfaceDefinition: EXPIRE key "seconds" Interface description: Set a key to expire after the current time "seconds". Returning 1 means the setting is successful, returning 0 means the key does not exist or the expiration time cannot be set. PEXPIRE interface definition: PEXPIRE key "milliseconds" interface description: Set a key to expire after the current time "milliseconds" (milliseconds). Returning 1 means the setting is successful, returning 0 means the key does not exist or the expiration time cannot be set.

2.EXPIREAT PEXPIREATE Returning 1 means the setting is successful, returning 0 means the key does not exist or the expiration time cannot be set. PEXPIREAT interface definition: PEXPIREAT key "milliseconds-timestamp" interface description: Set a key to expire after "milliseconds-timestamp" (timestamp (milliseconds)). Returning 1 means the setting is successful, returning 0 means the key does not exist or the expiration time cannot be set

3.TTL PTTLTTL interface Definition: TTL key interface description: Get the expiration time of the key. If the key has an expiration time, return the remaining survival time (seconds); if the key is permanent, return -1; if the key does not exist or has expired, return -2. PTTL interface definition: PTTL key interface description: Get the expiration time of the key. If the key has an expiration time, the remaining survival time (milliseconds) is returned; if the key is permanent, -1 is returned; if the key does not exist or has expired, -2 is returned.

4.PERSISTPERSIST interface Definition: PERSIST key interface description: Remove the expiration time of the key and convert it to a permanent state. If 1 is returned, the conversion is successful. If 0 is returned, it means that the key does not exist or has been in a permanent state before.

5.SETEXSETEX interfaceDefinition: SETEX key "seconds" "value" interface description: SETEX is logically equivalent to the operation of SET and EXPIRE merging, the difference is that SETEX is a command, and the execution of the command is atomic, so there will be no concurrency problems.

The above is the detailed content of What is the general redis cache time?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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