Documentation ¶
Overview ¶
Package rdidgen provides implementation of id generation using redis server.
Typical usage:
idgen := rdidgen.MustNew( rdidgen.WithRedisClient(client), rdidgen.WithKeyPrefix("object"), ) id, err := idgen.NextID() if err != nil { ... }
Index ¶
Constants ¶
const DefKeyPrefix = "entity"
DefKeyPrefix is the default prefix of the redis key that stores next id.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config structure with generator's configuration. Shouldn't be created manually.
type ConfigService ¶
ConfigService interface used to obtain configuration from somewhere into some specific structure.
type IDGen ¶
type IDGen struct {
// contains filtered or unexported fields
}
IDGen structure provides id generation functionality using redis client. Don't create manually, use the functions down below instead.
func MustNew ¶
MustNew function creates new redis id generator with provided options and panics on any error.
type Option ¶
Option function that is fed to New and MustNew. Obtain them using 'With' functions down below.
func WithConfig ¶
func WithConfig(service ConfigService, key string) Option
WithConfig option retrieves configuration from provided configuration service.
Example JSON configuration with all possible fields (if some are not present, defaults will be used):
{ "keyPrefix": "user" }
func WithKeyPrefix ¶
WithKeyPrefix option applies provided redis key prefix that stores next id. Default: "entity".
func WithRedisClient ¶
WithRedisClient option applies provided instance of redis client. If not provided, the default client will be used.