Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How long does the redis cache take

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How long does it take to cache redis? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

Redis expiration time

Redis Expiration introduction sometimes we don't want redis's key to exist all the time. For example, cache, CAPTCHA and other data, we hope that they can be automatically destroyed within a certain period of time. Redis provides commands that allow us to set the expiration time for key and let key be deleted automatically after it expires.

Commands related to redis expiration time

1.EXPIRE PEXPIREEXPIRE interface definition: EXPIRE key "seconds" interface description: sets a key to expire after the current time "seconds" (seconds). A return of 1 means the setting is successful, and a return of 0 means that key does not exist or the expiration time cannot be set. PEXPIRE interface definition: PEXPIRE key "milliseconds" interface description: sets a key to expire after the current time "milliseconds" (milliseconds). A return of 1 means the setting is successful, and a return of 0 means that key does not exist or the expiration time cannot be set.

2.EXPIREAT PEXPIREATEXPIREAT interface definition: EXPIREAT key "timestamp" interface description: sets a key to expire after "timestamp" (timestamp (seconds)). A return of 1 means the setting is successful, and a return of 0 means that key does not exist or the expiration time cannot be set. PEXPIREAT interface definition: PEXPIREAT key "milliseconds-timestamp" interface description: sets a key to expire after "milliseconds-timestamp" (timestamp (milliseconds). Return 1 means the setting is successful, and return 0 means that key does not exist or cannot set the expiration time

3.TTL PTTLTTL API definition: TTL key API description: gets the expiration time of key. Returns the remaining time to live (in seconds) if the key has expired,-1 if the key is permanent, and-2 if the key does not exist or has expired. PTTL API definition: PTTL key API description: gets the expiration time of key. Returns the remaining time to live in milliseconds if the key has expired,-1 if the key is permanent, and-2 if the key does not exist or has expired.

4.PERSISTPERSIST API definition: PERSIST key API description: removes the expiration time of the key and converts it to a permanent state. If 1 is returned, the conversion is successful. If 0 is returned, the key does not exist or has previously been in a permanent state.

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

So much for the answers to the long questions about redis caching. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report