Commit 3cfb8ec4 by 罗承锋

修改redis锁

parent 845575b4
......@@ -107,12 +107,6 @@
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
......
package com.winsun.utils;
import com.mysql.cj.util.TimeUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import sun.rmi.runtime.Log;
import javax.annotation.Resource;
......@@ -16,10 +17,6 @@ public class RedisLockUtil {
@Resource
private RedisTemplate<String, String> redisTemplate;
@Resource
private StringRedisTemplate stringRedisTemplate;
/**
* 创建锁
*
......@@ -30,17 +27,16 @@ public class RedisLockUtil {
*/
public synchronized Boolean redisLock(String key,String value,long releaseTime){
try{
boolean boo = redisTemplate.opsForValue().setIfAbsent(key,value,releaseTime, TimeUnit.MINUTES);
boolean boo = redisTemplate.opsForValue().setIfAbsent(key,value);
if(boo){
redisTemplate.expire(key, 10, TimeUnit.SECONDS);
return true;
}
return false;
}catch (Exception e){
e.getMessage();
}finally {
deleteLock(key);
return false;
redisTemplate.delete(key);
e.printStackTrace();
}
return false;
}
/**
* 根据key'删除锁
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment