Skip to content

Commit

Permalink
💄 add readme by english
Browse files Browse the repository at this point in the history
  • Loading branch information
disaster1-tesk committed Jun 24, 2023
1 parent 91987ea commit 373ce03
Show file tree
Hide file tree
Showing 2 changed files with 266 additions and 38 deletions.
227 changes: 227 additions & 0 deletions README-CH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<p align="center">
<img width="400" src="https://gitee.com/d__isaster/cornucopia/raw/master/img/lock%20layer.png">
</p>


## 🔥特性(Features)
- 🚀 开箱即用
- 🍄 自动续锁
- 🔆 锁重试
- ⛏️ 可重入锁
- ⚙️ 声明式加锁
- ..........(待续)
## 🖥 环境要求 (Environment Required)
- redis v6.0.0+
- jdk 1.8+
- ......

## 🌎 整体架构 (Architecture)

....(待续)

## ☀️ 快速开始(Quick Start)

### 💊 依赖 (Dependency)
#### java、spring
```java
<dependency>
<groupId>io.github.disaster1-tesk</groupId>
<artifactId>lock-layer-core</artifactId>
<version>1.1.0</version>
</dependency>
```
#### springboot
```java
<dependency>
<groupId>io.github.disaster1-tesk</groupId>
<artifactId>lock-layer-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
```
### 🛁 使用
#### java原生

```java
#配置相关
LockManager lockManager = LockManager.create(LockConfig.build().setClient(new JedisClient(new JedisPool("127.0.0.1", 6379, null, "123456"))));
RedisLockLayerLayer redisLockLayer = new RedisLockLayerLayer(lockManager);
```
```java
#使用
Thread thread = new Thread(() -> {
redisLockLayer.tryLock("test_key");
try {
Thread.sleep(10000);
redisLockLayer.unLock("test_key");
} catch (InterruptedException e) {
e.printStackTrace();
}
}, "thread1");
Thread thread1 = new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
redisLockLayer.tryLock("test_key");
}, "thread2");
thread.start();
thread1.start();
while (true) {

}
```

#### spring
....(待续)
#### springboot

##### 1.配置

```yaml
#lock layer只是复用了spring-redis的配置并不会影响其spring-redis 的正常使用
spring:
redis:
port: 6379
host: localhost
password: 123456
jedis:
pool:
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
timeout: 2000

lock:
layer:
declaration:
enable: true #此配置用来开启声明式加锁功能,默认为false
```
##### 2.使用
###### 1.编程式使用
只需DI LockLayer 到类中即可使用
```java
@Autowired
private LockLayer redisLockLayer;
```

###### 2.声明式使用

```java
@Component
public class Lock {

@LockLayer(key = "test_key", expireTime = 100)
public void lock() {

}

@LockLayer(key = "test_key", expireTime = 100, reentryLock = true)
public void retryLock() {

}

#当注解标注的方法中抛异常,lock layer 会自动释放锁
@LockLayer(key = "test_key", expireTime = 10)
public void lockException() {
throw new RuntimeException();
}
}

```

```java
@SpringBootApplication
public class LockLayerApplication {
@Autowired
private LockLayer redisLockLayer;
@Autowired
private Lock lock;

public static void main(String[] args) {
SpringApplication.run(LockLayerApplication.class, args);
}

@Bean
public ApplicationRunner applicationRunner1(){
return args -> {
lock.lock();
lock.lockException();
};
}

@Bean
public ApplicationRunner applicationRunner(){
return args -> {
Thread thread = new Thread(() -> {
redisLockLayer.tryLock("test_key");
try {
Thread.sleep(10000);
redisLockLayer.unLock("test_key");
} catch (InterruptedException e) {
e.printStackTrace();
}
}, "thread1");
Thread thread1 = new Thread(() -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
redisLockLayer.tryLock("test_key");
}, "thread2");
thread.start();
thread1.start();
};
}
}
```
## 💐 配置 (Configuration)

如果不进行动态配置则会使用lock layer默认的配置

```yaml
#全局设置,需要注意的是,此yml文件名必须是lock-layer-extend.yml,如果是其他文件名,lock layer将无法加载其配置
lock:
layer:
max_expire_count: 3 #配置最大续锁的次数
max_retry_time: 30000 #最大锁重试时间,超过此时间则会锁失败
max_expire_time : 60 #最大续锁时间,此配置与max_expire_count共同
max_reentry_count: 3 #可重入次数
log:
enable: true #开启lock layer日志,默认不开启
```
## 🧽 扩展接口 (Extend Api)
lock layer 提供LockHeatProcessor、LockProcessor两个接口让开发人员可以在加锁成功、失败、锁续时超时时进行扩展操作
```java
#LockHeatProcessor接口作用锁续时超时时进行的后续操作扩展接口
@Service
public class LockHeatProcessorImpl implements LockHeatProcessor {
@Override
public void lockHeartRemovedProcessor(LockHeartBeatEntity value) {
System.out.println(value.getExpireCount());
}
}
```

```java
#LockProcessor接口作用加锁成功、失败时的后续操作扩展接口
@Service
public class LockProcessorImpl implements LockProcessor {
@Override
public void failLockProcessor(LockEntity lockEntity) {
System.out.println("lock failure"+lockEntity.get_key());
}

@Override
public void successLockProcessor(LockEntity lockEntity) {
System.out.println("lock success"+lockEntity.get_key());
}
}
```

77 changes: 39 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
<img width="400" src="https://gitee.com/d__isaster/cornucopia/raw/master/img/lock%20layer.png">
</p>


## 🔥特性(Features)
- 🚀 开箱即用
- 🍄 自动续锁
- 🔆 锁重试
- ⛏️ 可重入锁
- ⚙️ 声明式加锁
- ..........(待续)
## 🖥 环境要求 (Environment Required)
[Chinese]()

## 🔥Features
- 🚀 Out of the box
- 🍄 Automatic relocking
- 🔆 Lock retry
- ⛏️ Reentrant lock
- ⚙️ Declarative locking
- ..........(To be continued)
## 🖥 Environment Required
- redis v6.0.0+
- jdk 1.8+
- ......

## 🌎 整体架构 (Architecture
## 🌎 Architecture

....(待续
....(To be continued

## ☀️ 快速开始(Quick Start
## ☀️ Quick Start

### 💊 依赖 (Dependency)
### 💊 Dependency
#### java、spring
```java
<dependency>
Expand All @@ -38,16 +39,16 @@
<version>1.1.0</version>
</dependency>
```
### 🛁 使用
#### java原生
### 🛁 USE
#### java primitive

```java
#配置相关
# About Configuration
LockManager lockManager = LockManager.create(LockConfig.build().setClient(new JedisClient(new JedisPool("127.0.0.1", 6379, null, "123456"))));
RedisLockLayerLayer redisLockLayer = new RedisLockLayerLayer(lockManager);
```
```java
#使用
#Using
Thread thread = new Thread(() -> {
redisLockLayer.tryLock("test_key");
try {
Expand All @@ -73,13 +74,13 @@ Thread thread = new Thread(() -> {
```

#### spring
....(待续
....(To be continued
#### springboot

##### 1.配置
##### 1.Configuration

```yaml
#lock layer只是复用了spring-redis的配置并不会影响其spring-redis 的正常使用
# If the lock layer reuses the configuration of spring-redis, the normal use of spring-redis will not be affected
spring:
redis:
port: 6379
Expand All @@ -96,20 +97,20 @@ spring:
lock:
layer:
declaration:
enable: true #此配置用来开启声明式加锁功能,默认为false
enable: true # This configuration enables declarative locking. The default value is false
```
##### 2.使用
##### 2.Using
###### 1.编程式使用
###### 1.Programmatic use
只需DI LockLayer 到类中即可使用
Just DI LockLayer into the class to use
```java
@Autowired
private LockLayer redisLockLayer;
```

###### 2.声明式使用
###### 2.Declarative use

```java
@Component
Expand All @@ -125,7 +126,7 @@ public class Lock {

}

#当注解标注的方法中抛异常,lock layer 会自动释放锁
//When an exception is thrown in a annotated method, the lock layer automatically releases the lock
@LockLayer(key = "test_key", expireTime = 10)
public void lockException() {
throw new RuntimeException();
Expand Down Expand Up @@ -180,26 +181,26 @@ public class LockLayerApplication {
}
}
```
## 💐 配置 (Configuration
## 💐 Configuration

如果不进行动态配置则会使用lock layer默认的配置
If the lock layer is not dynamically configured, the default lock layer is used

```yaml
#全局设置,需要注意的是,此yml文件名必须是lock-layer-extend.yml,如果是其他文件名,lock layer将无法加载其配置
#Global Settings, it should be noted that this yml file name must be lock-layer-extend.yml, if it is any other file name, the lock layer will not be able to load its configuration
lock:
layer:
max_expire_count: 3 #配置最大续锁的次数
max_retry_time: 30000 #最大锁重试时间,超过此时间则会锁失败
max_expire_time : 60 #最大续锁时间,此配置与max_expire_count共同
max_reentry_count: 3 #可重入次数
max_expire_count: 3 # The maximum number of consecutive locks was set
max_retry_time: 30000 # The maximum lock retry time, after which the lock fails
max_expire_time : 60 # Maximum renewal time, which is the same as max_expire_count
max_reentry_count: 3 # The number of reentrants allowed
log:
enable: true #开启lock layer日志,默认不开启
enable: true # Enable lock layer logs. This function is disabled by default
```
## 🧽 扩展接口 (Extend Api)
lock layer 提供LockHeatProcessor、LockProcessor两个接口让开发人员可以在加锁成功、失败、锁续时超时时进行扩展操作
## 🧽 Extend Interface
The lock layer provides two interfaces, LockHeatProcessor and LockProcessor, to allow developers to expand operations when locks are successfully added, fail to be added, and when the lock duration times out
```java
#LockHeatProcessor接口作用锁续时超时时进行的后续操作扩展接口
//LockHeatProcessor Indicates the interface for subsequent operations performed when the lock timeout occurs
@Service
public class LockHeatProcessorImpl implements LockHeatProcessor {
@Override
Expand All @@ -210,7 +211,7 @@ public class LockHeatProcessorImpl implements LockHeatProcessor {
```

```java
#LockProcessor接口作用加锁成功、失败时的后续操作扩展接口
//LockProcessor Indicates the extension interface for subsequent operations when a lock succeeds or fails
@Service
public class LockProcessorImpl implements LockProcessor {
@Override
Expand Down

0 comments on commit 373ce03

Please sign in to comment.