Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
device-new-platform
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
赵啸非
device-new-platform
Commits
3d944af7
Commit
3d944af7
authored
Jun 17, 2023
by
赵啸非
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修正redis 最大连接数
parent
29ff6d88
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
27 deletions
+26
-27
common-lib/src/main/java/com/mortals/xhx/tools/lock/service/impl/RedisLockServiceImpl.java
...als/xhx/tools/lock/service/impl/RedisLockServiceImpl.java
+26
-27
No files found.
common-lib/src/main/java/com/mortals/xhx/tools/lock/service/impl/RedisLockServiceImpl.java
View file @
3d944af7
package
com.mortals.xhx.tools.lock.service.impl
;
package
com.mortals.xhx.tools.lock.service.impl
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.framework.service.ICacheService
;
import
com.mortals.xhx.common.keys.RedisCacheKeys
;
import
com.mortals.xhx.tools.lock.service.ILockService
;
import
com.mortals.xhx.tools.lock.service.ILockService
;
import
lombok.extern.apachecommons.CommonsLog
;
import
lombok.extern.apachecommons.CommonsLog
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
/**
/**
* redis 实现分布式锁机制
* redis 实现分布式锁机制
* @author zxfei
* @author zxfei
*/
*/
@CommonsLog
@CommonsLog
@Service
(
"redisLockService"
)
//
@Service("redisLockService")
//@ConditionalOnProperty("application.cache.redis")
//@ConditionalOnProperty("application.cache.redis")
public
class
RedisLockServiceImpl
implements
ILockService
{
public
class
RedisLockServiceImpl
implements
ILockService
{
private
static
ThreadLocal
<
String
>
threadLocal
=
new
ThreadLocal
<>();
private
static
ThreadLocal
<
String
>
threadLocal
=
new
ThreadLocal
<>();
...
@@ -28,32 +25,34 @@ public class RedisLockServiceImpl implements ILockService {
...
@@ -28,32 +25,34 @@ public class RedisLockServiceImpl implements ILockService {
@Override
@Override
public
boolean
lock
(
String
lockKey
,
Long
unlockSec
)
{
public
boolean
lock
(
String
lockKey
,
Long
unlockSec
)
{
try
{
return
false
;
boolean
ret
;
// try {
if
(
ObjectUtils
.
isEmpty
(
unlockSec
))
{
// boolean ret;
ret
=
cacheService
.
hincrBy
(
RedisCacheKeys
.
getCoopsDistributedLockKey
(),
lockKey
,
1
)
==
1
;
// if (ObjectUtils.isEmpty(unlockSec)) {
}
else
{
// ret = cacheService.hincrBy(RedisCacheKeys.getCoopsDistributedLockKey(), lockKey, 1) == 1;
ret
=
cacheService
.
hincrByForTime
(
RedisCacheKeys
.
getCoopsDistributedLockKey
(),
lockKey
,
1
,
unlockSec
)
==
1
;
// } else {
}
// ret = cacheService.hincrByForTime(RedisCacheKeys.getCoopsDistributedLockKey(), lockKey, 1, unlockSec) == 1;
if
(
ret
)
{
// }
threadLocal
.
set
(
lockKey
);
// if (ret) {
}
// threadLocal.set(lockKey);
return
ret
;
// }
}
catch
(
Exception
e
)
{
// return ret;
log
.
error
(
String
.
format
(
"分布式加锁出错 lockKey:%s%s"
,
lockKey
,
ObjectUtils
.
isEmpty
(
unlockSec
)
?
""
:
",unlockSec:"
+
unlockSec
),
e
);
// } catch (Exception e) {
return
false
;
// log.error(String.format("分布式加锁出错 lockKey:%s%s", lockKey, ObjectUtils.isEmpty(unlockSec) ? "" : ",unlockSec:" + unlockSec), e);
}
// return false;
// }
}
}
@Override
@Override
public
boolean
unlock
()
{
public
boolean
unlock
()
{
try
{
// try {
cacheService
.
hdel
(
RedisCacheKeys
.
getCoopsDistributedLockKey
(),
threadLocal
.
get
());
// cacheService.hdel(RedisCacheKeys.getCoopsDistributedLockKey(), threadLocal.get());
threadLocal
.
remove
();
// threadLocal.remove();
return
true
;
// return true;
}
catch
(
Exception
e
)
{
// } catch(Exception e) {
log
.
error
(
String
.
format
(
"分布式解锁出错 lockKey:%s"
,
threadLocal
.
get
()),
e
);
// log.error(String.format("分布式解锁出错 lockKey:%s", threadLocal.get()), e);
return
false
;
// return false;
}
// }
return
false
;
}
}
}
}
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