Get the App
SLTechnology News&Howtos  ›  Servers  › 

On the setting of the validity period of redis

Shulou Source: shulou.com Published: 2022-06-03 02:14:57 10月30日 Update

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

Tags: Time cache code data valid problem representative location sequence server never version result face project order service test validity period Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology Linux Apple Shulou Information