Skip to content

Commit 69a039f

Browse files
committed
代码加了注释
1 parent 57169fe commit 69a039f

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/target/
2+
.classpath
3+
.project
4+
.settings/
5+
*.bak
6+
.idea/

src/main/java/com/crossoverjie/distributed/lock/RedisLock.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,15 @@ private Object getConnection() {
7474
}
7575

7676
/**
77-
* Non-blocking lock
77+
* Non-blocking lock, default timeout :10s
7878
*
7979
* @param key lock business type
8080
* @param request value
8181
* @return true lock success
8282
* false lock fail
8383
*/
8484
public boolean tryLock(String key, String request) {
85-
//get connection
86-
Object connection = getConnection();
87-
String result ;
88-
if (connection instanceof Jedis){
89-
result = ((Jedis) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
90-
((Jedis) connection).close();
91-
}else {
92-
result = ((JedisCluster) connection).set(lockPrefix + key, request, SET_IF_NOT_EXIST, SET_WITH_EXPIRE_TIME, 10 * TIME);
93-
94-
}
95-
96-
if (LOCK_MSG.equals(result)) {
97-
return true;
98-
} else {
99-
return false;
100-
}
85+
return tryLock(key,request,10*TIME);
10186
}
10287

10388
/**

0 commit comments

Comments
 (0)