Files
eagle/internal/pkg/idalloc.go
2021-08-20 18:29:02 +08:00

22 lines
469 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package pkg ID 分配器主要使用redis进行分配
package pkg
import "github.com/go-eagle/eagle/pkg/redis"
// IDAlloc define struct
type IDAlloc struct {
idGenerator *redis.IDAlloc
}
// NewIDAlloc create a id alloc
func NewIDAlloc() *IDAlloc {
return &IDAlloc{
idGenerator: redis.NewIDAlloc(redis.RedisClient),
}
}
// GetUserID generate user id from redis
func (i *IDAlloc) GetUserID() (int64, error) {
return i.idGenerator.GetNewID("user_id", 1)
}