2023-08-03 18:57:39 +08:00
# Module `guid`
## Introduction
2025-02-15 12:23:22 +08:00
Module `guid` serves as a guid creator for other `JDevKit` modules. You can also use this module as a guid creator standards.
2023-08-03 18:57:39 +08:00
2025-06-17 16:32:57 +08:00
We have already implemented `SnowflakeGuidCreator` , you can also implement a custom guid creations by implementing `com.onixbyte.identitygenerator.IdentityGenerator` .
2023-08-03 18:57:39 +08:00
2025-02-15 12:23:22 +08:00
## Example usage
2023-08-03 18:57:39 +08:00
2025-02-15 12:23:22 +08:00
### A UUID creator
2023-08-03 18:57:39 +08:00
2025-02-15 12:23:22 +08:00
``` java
GuidCreator < UUID > uuidCreator = ( GuidCreator < UUID > ) UUID : : randomUUID ;
2023-08-03 18:57:39 +08:00
```
2025-02-15 12:23:22 +08:00
### A custom guid creator
Assume that you need serial guid creator.
``` java
@Component
public class CustomGuidCreator implementes GuidCreator < String > {
public final RedisTemplate < String , Long > serialRedisTemplate ;
@Autowired
public CustomGuidCreator ( RedisTemplate < String , Long > serialRedisTemplate ) {
this . serialRedisTemplate = serialRedisTemplate ;
}
@Override public String nextId ( ) {
return " SOME_PREFIX " + serialRedisTemplate . opsForValue ( ) . get ( " some_serial_key " ) ;
}
}
2023-08-03 18:57:39 +08:00
```