In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article uses easy-to-understand examples to introduce how to set the appropriate redis expiration time, the code is very detailed, interested friends can refer to, hope to be helpful to you.
Expiration time settin
Setting the expiration time refers to setting a time on the key so that the key can survive within this time, after which the key and its corresponding value are deleted. The expiration time is generally set in redis, rather than using the del command to eliminate the element.
Once the expiration time is set, the key can only be cleared, deleted, or rewritten by the command. These commands include del, set, getset, and all * store commands. These commands can only change the stored value of the value corresponding to key without changing the expiration time setting.
For example, using incr to change the value corresponding to key, using lpush to add a new element to lists, using hset to set the value of value corresponding to field, and so on, all of these operations do not affect the attribute of the expiration time that has been set to key.
1. Achieved through the expire command: demo:expire key 10-> sets the expiration time for a given key to 10 seconds
two。 Through the setex command: demo:setex key 10 value-> set the value of key to value and survive for 10 seconds-> value for key is of String type
The above two methods are aimed at the key and set the expiration time for it. If you want to set the expiration time for a certain part of the data in the value (other data types), you need to do so in other ways.
Key with an expiration time set can still be re-persisted using the persist command. (the PERSIST command removes the expiration time of a key)
Note: after the rename command renames the key, all the corresponding attributes of the original key are transferred. If key has an expiration time set and has not been deleted, the expiration time will be transferred to the new key after renaming with the rename command.
If a negative value is passed as a parameter when expire or pexpire is called and the timestamp has passed when expireat or pexpireat is called, then the key will be deleted directly instead of waiting for expiration.
Refresh expiration time
A key with an expiration time set can still call expire to update its expiration time.
Return value
Setting the expiration time returns an integer value
1) if the expiration time is set successfully, return 1
2) if the setting fails or key does not exist, 0 is returned.
On how to set the appropriate redis expiration time to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.