driver

package
v3.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const GlobalKeyPrefix = "Distributed-Cron:"

GlobalKeyPrefix is a global redis key prefix

View Source
const (
	OptionTypeTimeout = 0x600
)

Variables

View Source
var KeyPreFix string

Functions

func GetKeyPre

func GetKeyPre(serviceName string) string

func GetNodeId

func GetNodeId(serviceName string) string

func GetNodeIdKeyPrefix added in v3.8.2

func GetNodeIdKeyPrefix() string

func SetNodeIdKeyPrefix added in v3.8.2

func SetNodeIdKeyPrefix(prefix string)

func TimePre added in v3.8.0

func TimePre(t time.Time, preDuration time.Duration) int64

Types

type DriverV2 added in v3.8.0

type DriverV2 interface {
	// init driver
	Init(serviceName string, opts ...Option)
	// get nodeID
	NodeID() string
	// get nodes
	GetNodes(ctx context.Context) (nodes []string, err error)

	// register node to remote server (like etcd/redis),
	// will create a goroutine to keep the connection.
	// And then continue for other work.
	Start(ctx context.Context) (err error)

	// stop the goroutine of keep connection.
	Stop(ctx context.Context) (err error)

	WithOption(opt Option) (err error)
}

There is only one driver for one task. Tips for write a user-defined Driver by yourself.

  1. Confirm that `Stop` and `Start` can be called for more times.
  2. Must make `GetNodes` will return error when timeout.

func NewEtcdDriver added in v3.8.0

func NewEtcdDriver(etcdCli *etcdv3.Client) DriverV2

func NewRedisDriver added in v3.8.0

func NewRedisDriver(redisClient *redis.Client) DriverV2

func NewRedisZSetDriver added in v3.8.0

func NewRedisZSetDriver(redisClient *redis.Client) DriverV2

type EtcdDriver added in v3.8.0

type EtcdDriver struct {
	// contains filtered or unexported fields
}

func (*EtcdDriver) GetNodes added in v3.8.0

func (e *EtcdDriver) GetNodes(ctx context.Context) (nodes []string, err error)

func (*EtcdDriver) Init added in v3.8.0

func (e *EtcdDriver) Init(serverName string, opts ...Option)

func (*EtcdDriver) NodeID added in v3.8.0

func (e *EtcdDriver) NodeID() string

func (*EtcdDriver) Start added in v3.8.0

func (e *EtcdDriver) Start(ctx context.Context) (err error)

func (*EtcdDriver) Stop added in v3.8.0

func (e *EtcdDriver) Stop(ctx context.Context) (err error)

func (*EtcdDriver) WithOption added in v3.8.0

func (e *EtcdDriver) WithOption(opt Option) (err error)

type Option added in v3.8.0

type Option interface {
	Type() int
}

type RedisDriver added in v3.8.0

type RedisDriver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RedisDriver) GetNodes added in v3.8.0

func (rd *RedisDriver) GetNodes(ctx context.Context) (nodes []string, err error)

func (*RedisDriver) Init added in v3.8.0

func (rd *RedisDriver) Init(serviceName string, opts ...Option)

func (*RedisDriver) NodeID added in v3.8.0

func (rd *RedisDriver) NodeID() string

func (*RedisDriver) Start added in v3.8.0

func (rd *RedisDriver) Start(ctx context.Context) (err error)

func (*RedisDriver) Stop added in v3.8.0

func (rd *RedisDriver) Stop(ctx context.Context) (err error)

func (*RedisDriver) WithOption added in v3.8.0

func (rd *RedisDriver) WithOption(opt Option) (err error)

type RedisZSetDriver added in v3.8.0

type RedisZSetDriver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*RedisZSetDriver) GetNodes added in v3.8.0

func (rd *RedisZSetDriver) GetNodes(ctx context.Context) (nodes []string, err error)

func (*RedisZSetDriver) Init added in v3.8.0

func (rd *RedisZSetDriver) Init(serviceName string, opts ...Option)

func (*RedisZSetDriver) NodeID added in v3.8.0

func (rd *RedisZSetDriver) NodeID() string

func (*RedisZSetDriver) Start added in v3.8.0

func (rd *RedisZSetDriver) Start(ctx context.Context) (err error)

func (*RedisZSetDriver) Stop added in v3.8.0

func (rd *RedisZSetDriver) Stop(ctx context.Context) (err error)

func (*RedisZSetDriver) WithOption added in v3.8.0

func (rd *RedisZSetDriver) WithOption(opt Option) (err error)

type TimeoutOption added in v3.8.0

type TimeoutOption struct {
	// contains filtered or unexported fields
}

func NewTimeoutOption added in v3.8.0

func NewTimeoutOption(timeout time.Duration) TimeoutOption

func (TimeoutOption) Type added in v3.8.0

func (to TimeoutOption) Type() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL