On the setting of the validity period of redis
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