|
@@ -4,7 +4,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
+import java.util.logging.Handler;
|
|
|
|
|
|
@Component
|
|
@Component
|
|
public class RedisLock {
|
|
public class RedisLock {
|
|
@@ -50,16 +53,14 @@ public class RedisLock {
|
|
*/
|
|
*/
|
|
public void unlock(String key, String value) {
|
|
public void unlock(String key, String value) {
|
|
try {
|
|
try {
|
|
- String currentValue = String.valueOf(redisTemplate.opsForValue().get(key));
|
|
|
|
- if (!StringUtils.isEmpty(currentValue) && currentValue.equals(value)) {
|
|
|
|
- redisTemplate.opsForValue().getOperations().delete(key);
|
|
|
|
- }
|
|
|
|
|
|
+ redisTemplate.delete(key);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void sendDataLock(String key, String value) {
|
|
public void sendDataLock(String key, String value) {
|
|
|
|
+// redisTemplate.opsForHash().put("ALARM-DATA-LOCK",key,value);
|
|
redisTemplate.opsForValue().setIfAbsent(key, value);
|
|
redisTemplate.opsForValue().setIfAbsent(key, value);
|
|
redisTemplate.expire(key,10, TimeUnit.SECONDS);
|
|
redisTemplate.expire(key,10, TimeUnit.SECONDS);
|
|
}
|
|
}
|