Skip to content

onixbyte/identity-generator

Repository files navigation

Identity Generator

Introduction

Identity generator serves as a identity generator. You can also use this module as a guid generator standards.

We have already implemented SnowflakeGuidGenerator with snowflake algorithm open-sourced by X (former Twitter), you can also implement a custom guid creations by implementing com.onixbyte.identity.IdentityGenerator.

Example usage

A UUID creator

IdentityGenerator<UUID> uuidCreator = (IdentityGenerator<UUID>) UUID::randomUUID;

A custom guid creator

Assume that you need serial guid creator.

@Component
public class CustomGuidGenerator implementes IdentityGenerator<String> {
    
    public final RedisTemplate<String, Long> serialRedisTemplate;
    
    @Autowired
    public CustomGuidGenerator(RedisTemplate<String, Long> serialRedisTemplate) {
        this.serialRedisTemplate = serialRedisTemplate;
    }
    
    @Override
    public String nextId() {
        return "SOME_PREFIX" + serialRedisTemplate.opsForValue().get("some_serial_key");
    }
}

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages