添加接口防抖
This commit is contained in:
@@ -5,10 +5,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@Component
|
||||
@@ -583,4 +580,15 @@ public class RedisUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean lock(String key, long timeout, TimeUnit timeUnit) {
|
||||
String value = UUID.randomUUID().toString();
|
||||
Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
|
||||
return success != null && success;
|
||||
}
|
||||
|
||||
|
||||
public void releaseLock(String key) {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user