public void test() {
String key = AAAA;
if (check(key)) {
try {
//具体逻辑
} catch (Exception e) {
LOG.error(e.getMessage(), e);
} finally {
clear(key);
}
}
}
private boolean check(String key) {
RedisAtomicLong atomicLong = new RedisAtomicLong(key, redisConnectionFactory);
atomicLong.expire(1, TimeUnit.HOURS);
long num = atomicLong.getAndIncrement();
if (num == 1L) {
return true;
}
return false;
}
private void clear(String key) {
RedisAtomicLong atomicLong = new RedisAtomicLong(key, redisConnectionFactory);
atomicLong.set(0L);
}
@Autowired
private RedisConnectionFactory redisConnectionFactory;