| | |
| | | try { |
| | | redisTemplate.opsForValue().set(key, value); |
| | | redisTemplate.execute((RedisCallback<Void>) connection -> null); |
| | | return true; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 普通缓存放入 |
| | | * |
| | | * @param key 键 |
| | | * @param value 值 |
| | | * @return true成功 false失败 |
| | | */ |
| | | public boolean setSync(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); |