[Feature] add for new
This commit is contained in:
@@ -44,7 +44,7 @@ public final class LockBs implements ILock{
|
||||
* 缓存策略
|
||||
* @since 0.0.4
|
||||
*/
|
||||
private ICommonCacheService commonCacheService = JedisRedisServiceFactory.simple("127.0.0.1", 6379);
|
||||
private ICommonCacheService cache = JedisRedisServiceFactory.pooled("127.0.0.1", 6379);
|
||||
|
||||
/**
|
||||
* 锁支持策略
|
||||
@@ -70,10 +70,10 @@ public final class LockBs implements ILock{
|
||||
return this;
|
||||
}
|
||||
|
||||
public LockBs commonCacheService(ICommonCacheService commonCacheService) {
|
||||
ArgUtil.notNull(commonCacheService, "commonCacheService");
|
||||
public LockBs cache(ICommonCacheService cache) {
|
||||
ArgUtil.notNull(cache, "cache");
|
||||
|
||||
this.commonCacheService = commonCacheService;
|
||||
this.cache = cache;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ public final class LockBs implements ILock{
|
||||
public LockBs init() {
|
||||
this.lockSupportContext = LockSupportContext.newInstance()
|
||||
.id(id)
|
||||
.commonCacheService(commonCacheService)
|
||||
.cache(cache)
|
||||
.lockExpireMills(lockExpireMills);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -44,11 +44,11 @@ public class LockSupportContext implements ILockSupportContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICommonCacheService commonCacheService() {
|
||||
public ICommonCacheService cache() {
|
||||
return commonCacheService;
|
||||
}
|
||||
|
||||
public LockSupportContext commonCacheService(ICommonCacheService commonCacheService) {
|
||||
public LockSupportContext cache(ICommonCacheService commonCacheService) {
|
||||
this.commonCacheService = commonCacheService;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RedisLockSupport implements ILockSupport {
|
||||
IdThreadLocalHelper.put(requestId);
|
||||
log.info("开始尝试获取锁 requestId: {}", requestId);
|
||||
|
||||
final ICommonCacheService commonCacheService = context.commonCacheService();
|
||||
final ICommonCacheService commonCacheService = context.cache();
|
||||
|
||||
final int lockExpireMills = context.lockExpireMills();
|
||||
|
||||
@@ -79,7 +79,7 @@ public class RedisLockSupport implements ILockSupport {
|
||||
String requestId = IdThreadLocalHelper.get();
|
||||
log.info("开始尝试释放锁 requestId: {}", requestId);
|
||||
|
||||
final ICommonCacheService commonCacheService = context.commonCacheService();
|
||||
final ICommonCacheService commonCacheService = context.cache();
|
||||
String script = "if redis.call('get', KEYS[1]) == ARGV[1] then return redis.call('del', KEYS[1]) else return 0 end";
|
||||
Object result = commonCacheService.eval(script, Collections.singletonList(key), Collections.singletonList(requestId));
|
||||
return JedisConst.RELEASE_SUCCESS.equals(result);
|
||||
|
||||
Reference in New Issue
Block a user