Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to set the redis validity period

Shulou Source: shulou.com Published: 2022-06-01 11:16:16 10月01日 Update

This article mainly explains "how to set the period of validity of redis". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to set the validity period of redis".

1 about redisKey construction

Private String key (RedisShip I) {

/ / return String.format ("% s_%d_%d_%d", KEY_PREFIX, getNow (), i.getPosTime (), i.getGrid ())

Return String.format ("% s:%d:%d:%d", KEY_PREFIX, getNow (), i.getPosTime (), i.getGrid ());}

2 about getting the current time 0: 00

Public Integer getNow () {/ / Calendar calendar = Calendar.getInstance (); / / calendar.setTime (new Date ()); / / calendar.set (calendar.get (Calendar.YEAR), / / calendar.get (Calendar.MONTH), calendar.get (Calendar.DATE), / / 0,0,0); return Math.toIntExact (Instant.now (). GetEpochSecond () / 86400 * 86400);}

3 about setting the period of validity of redis

Private static final Duration DURATION = Duration.ofDays (2)

Connection.expire (key, DURATION.getSeconds ())

Thank you for reading, the above is the content of "how to set the period of validity of redis". After the study of this article, I believe you have a deeper understanding of how to set the validity period of redis, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Validity validity learning content that is ideas situations articles time more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Shulou Tech Info Shulou Technology Xiaomi NVidia