From cbc22b3411012f54149249d70564c400f86983ac Mon Sep 17 00:00:00 2001 From: boylong12 Date: Thu, 24 Mar 2022 16:38:16 +0800 Subject: [PATCH] upd 0.0.3 Change-Id: Ia7142f4eb705cfdd1c2d6ce7b1eeffc64fa0b7fb --- dlock-spring-boot-starter/pom.xml | 4 ++-- .../main/java/com/ldcr/dlock/handler/BaseLockHandler.java | 5 +++-- .../main/java/com/ldcr/dlock/util/LockKeyGenerator.java | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dlock-spring-boot-starter/pom.xml b/dlock-spring-boot-starter/pom.xml index 552773a..a24cc6e 100644 --- a/dlock-spring-boot-starter/pom.xml +++ b/dlock-spring-boot-starter/pom.xml @@ -7,7 +7,7 @@ com.github.boylong12 dlock-spring-boot-starter - 0.0.2 + 0.0.3 jar dlock-spring-boot-starter @@ -25,7 +25,7 @@ scm:git@github.com:boylong12/dlock.git scm:git@github.com:boylong12/dlock.git git@github.com:boylong12/dlock.git - v0.0.2.release + v0.0.3.release diff --git a/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/handler/BaseLockHandler.java b/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/handler/BaseLockHandler.java index bbcd43a..f552407 100644 --- a/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/handler/BaseLockHandler.java +++ b/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/handler/BaseLockHandler.java @@ -46,8 +46,9 @@ public boolean tryLock(String key, String value, long expireTime) { /** * 解锁: - * 匹配随机数,删除redis上的特定的key数据, - * 要保证获取数据,判断一致以及删除数据三个操作是原子性 + * 1 需要验证value是和加锁的一致才删除key。 + * 这是避免了一种情况:假设A获取了锁,过期时间30s,此时35s之后,锁已经自动释放了,A去释放锁,但是此时可能B获取了锁。A客户端就不能删除B的锁了。 + * 2 删除redis上的特定的key数据,要保证获取数据,判断一致以及删除数据三个操作是原子性 * 执行如下lua脚本: * if redis.call('get', KEYS[1]) == ARGV[1] then * return redis.call('del', KEYS[1]) diff --git a/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/util/LockKeyGenerator.java b/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/util/LockKeyGenerator.java index 0204a0b..91c6459 100644 --- a/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/util/LockKeyGenerator.java +++ b/dlock-spring-boot-starter/src/main/java/com/ldcr/dlock/util/LockKeyGenerator.java @@ -64,8 +64,11 @@ private String getSpelDefinitionKey(String[] definitionKeys, Method method, Obje List definitionKeyList = new ArrayList<>(definitionKeys.length); for (String definitionKey : definitionKeys) { if (definitionKey != null && !definitionKey.isEmpty()) { - String key = PARSER.parseExpression(definitionKey).getValue(context).toString(); - definitionKeyList.add(key); + Object obj = PARSER.parseExpression(definitionKey).getValue(context); + if (obj != null) { + String key = obj.toString(); + definitionKeyList.add(key); + } } } return StringUtils.collectionToDelimitedString(definitionKeyList, "-", "", "");