File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,7 @@ UidGenerator是Java实现的, 基于[Snowflake](https://github.com/twitter/snowf
67
67
### spring方式 请参见 [ 百度UidGenerator] ( https://github.com/baidu/uid-generator )
68
68
69
69
### 数据库(可选)
70
- 如使用数据库实现的Worker node id分配器,需要先建立表 WORKER_NODE, 脚本:
70
+ 如果使用数据库实现的Worker node id分配器,需要先建立表 WORKER_NODE, 脚本:
71
71
``` sql
72
72
DROP TABLE IF EXISTS WORKER_NODE;
73
73
CREATE TABLE WORKER_NODE
@@ -159,3 +159,29 @@ spring:
159
159
}
160
160
161
161
```
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 )
You can’t perform that action at this time.
0 commit comments