[Feature] add for new

This commit is contained in:
binbin.hou
2022-12-07 16:54:37 +08:00
parent c0e3cc4bf2
commit 8bf1df19c2

View File

@@ -32,7 +32,7 @@ maven 3.x+
<dependency> <dependency>
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<artifactId>lock-core</artifactId> <artifactId>lock-core</artifactId>
<version>0.0.4</version> <version>1.0.0</version>
</dependency> </dependency>
``` ```
@@ -41,20 +41,19 @@ maven 3.x+
基于本地 redis 的测试案例。 基于本地 redis 的测试案例。
```java ```java
Jedis jedis = new Jedis("127.0.0.1", 6379); ILock lock = LockBs.newInstance()
IOperator operator = new JedisOperator(jedis); .init();
// 获取锁
ILock lock = LockBs.newInstance(operator).lock();
String key = "ddd";
try { try {
boolean lockResult = lock.tryLock(); // 加锁
System.out.println(lockResult); lock.tryLock(key);
// 业务处理 System.out.println("业务处理");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); throw new RuntimeException(e);
} finally { } finally {
lock.unlock(); // 释放锁
lock.unlock(key);
} }
``` ```