Skip to content

Commit f4e4077

Browse files
committed
read me
1 parent 6f12566 commit f4e4077

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ UidGenerator是Java实现的, 基于[Snowflake](https://github.com/twitter/snowf
6767
### spring方式 请参见 [百度UidGenerator](https://github.com/baidu/uid-generator)
6868

6969
### 数据库(可选)
70-
如使用数据库实现的Worker node id分配器,需要先建立表 WORKER_NODE, 脚本:
70+
如果使用数据库实现的Worker node id分配器,需要先建立表 WORKER_NODE, 脚本:
7171
```sql
7272
DROP TABLE IF EXISTS WORKER_NODE;
7373
CREATE TABLE WORKER_NODE
@@ -159,3 +159,29 @@ spring:
159159
}
160160

161161
```
162+
163+
### 使用
164+
165+
166+
```java
167+
168+
//实时生成
169+
//@Resource
170+
//private UidGenerator defaultUidGenerator;
171+
172+
//生成一次id之后,按序列号+1生成一批id,缓存,供之后请求
173+
@Resource
174+
private UidGenerator cachedUidGenerator;
175+
176+
@Test
177+
public void testSerialGenerate() {
178+
// Generate UID
179+
long uid = cachedUidGenerator.getUID();
180+
181+
// Parse UID into [Timestamp, WorkerId, Sequence]
182+
// {"UID":"450795408770","timestamp":"2019-02-20 14:55:39","workerId":"27","sequence":"2"}
183+
System.out.println(cachedUidGenerator.parseUID(uid));
184+
185+
}
186+
```
187+
**defaultUidGenerator****cachedUidGenerator** 的区别和选择方式请参见 [百度UidGenerator](https://github.com/baidu/uid-generator)

0 commit comments

Comments
 (0)