Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gdtel-gztel-school-center
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴学德
gdtel-gztel-school-center
Commits
3cfb8ec4
Commit
3cfb8ec4
authored
Feb 02, 2021
by
罗承锋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改redis锁
parent
845575b4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
17 deletions
+7
-17
common/pom.xml
+0
-6
common/src/main/java/com/winsun/utils/RedisLockUtil.java
+7
-11
No files found.
common/pom.xml
View file @
3cfb8ec4
...
...
@@ -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>
...
...
common/src/main/java/com/winsun/utils/RedisLockUtil.java
View file @
3cfb8ec4
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'删除锁
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment