From 1a55c3c417343fc26c54a5c76f128103561e07b8 Mon Sep 17 00:00:00 2001 From: laobinggan <56704330+laobinggan@users.noreply.github.com> Date: Thu, 15 Aug 2024 09:15:33 +0800 Subject: [PATCH] Update getting-started.md (#588) --- documentation/docs/guide/getting-started.md | 44 ++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/documentation/docs/guide/getting-started.md b/documentation/docs/guide/getting-started.md index 5dc45b30e7..fff2a52aa4 100644 --- a/documentation/docs/guide/getting-started.md +++ b/documentation/docs/guide/getting-started.md @@ -91,6 +91,48 @@ cosid: DefaultIdGeneratorProvider.INSTANCE.getShare(); ``` +> 通过`yml`文件配置`provider`创建多个`生成器` + +``` +spring: + data: + redis: + host: localhost # Redis 分发器直接依赖 spring-data-redis,这样可以省去额外的配置。 +cosid: + namespace: ${spring.application.name} + machine: + enabled: false # 可选,当需要使用雪花算法时,需要设置为 true + distributor: + type: redis + segment: + enabled: true # 可选,当需要使用号段算法时,需要设置为 true + distributor: + type: redis + provider: + order: + offset: 10000 + item: + offset: 10000 +``` + +>通过`代码`创建多个多个`生成器` + +```java + @Resource + IdGeneratorProvider provider; + @Resource + StringRedisTemplate stringRedisTemplate; + + public void createProvider(String idName) { + SpringRedisIdSegmentDistributor springRedisIdSegmentDistributor = new SpringRedisIdSegmentDistributor("namespace", "idName", stringRedisTemplate); + SegmentChainId segmentId = new SegmentChainId(springRedisIdSegmentDistributor); + + provider.set(idName, segmentId); + } +``` + + + ## Examples -开发者可以通过 [CosId-Examples](https://github.com/Ahoo-Wang/CosId/tree/main/examples) 的学习快速开启 `CosId` 之旅。 \ No newline at end of file +开发者可以通过 [CosId-Examples](https://github.com/Ahoo-Wang/CosId/tree/main/examples) 的学习快速开启 `CosId` 之旅。