|  |  | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.toolkit.StringUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.data.redis.core.RedisCallback; | 
 |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
 |  |  | import org.springframework.data.redis.core.StringRedisTemplate; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  | 
 |  |  |     public boolean set(String key, Object value) { | 
 |  |  |         try { | 
 |  |  |             redisTemplate.opsForValue().set(key, value); | 
 |  |  |             redisTemplate.execute((RedisCallback<Void>) connection -> null); | 
 |  |  |             long start = System.currentTimeMillis(); | 
 |  |  |             while (System.currentTimeMillis() - start < 10000) {//有效期10s | 
 |  |  |                 Object o = redisTemplate.opsForValue().get(key); | 
 |  |  | 
 |  |  |             } else { | 
 |  |  |                 set(key, value); | 
 |  |  |             } | 
 |  |  |             redisTemplate.execute((RedisCallback<Void>) connection -> null); | 
 |  |  |             return true; | 
 |  |  |         } catch (Exception e) { | 
 |  |  |             e.printStackTrace(); |