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

On the setting of the validity period of redis

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Redis server version: 3.0.7

The project introduces the jar package: spring-data-redis-1.6.1.RELEASE.jar,jedis-2.8.1.jar

A problem encountered with redisTemplate is recorded here:

Public String getIconResourceByCache (String model) {/ / first get data from cache String hashkey = "version"; String versionVal = (String) redisTemplate.boundHashOps (VERSION_KEY). Get (hashkey); Long expire = redisTemplate.boundHashOps (VERSION_KEY). GetExpire (); System.out.println ("redis validity time:" + expire+ "S"); if (versionVal = = null) {System.out.println ("redis cache does not have data, set cache after re-acquisition") VersionVal = "temp test"; / / put the results in the cache, pay attention to the order (set the value first, and then set the expiration time), otherwise the expiration time will not take effect redisTemplate.opsForHash (). Put (VERSION_KEY, hashkey, versionVal); redisTemplate.expire (VERSION_KEY, Constants.EXPIRE, TimeUnit.SECONDS);} return versionVal;}

Code if code body, the last two lines of code, if the exchange of places, then the above expire expiration time is always-1, which means never expire

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

Servers

Wechat

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

12
Report