synlock

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 16 Imported by: 0

README

Synlock status

Allows to construct distributed locks engine if you have:

  • Redis
  • Consul (not implemented yet)
  • Postgres (not implemented yet)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRedisInvalidAddr     = errors.New("invalid redis address")
	ErrRedisKeyDoesNotExist = errors.New("key does not exist")
	ErrRedisInvalidPrefix   = errors.New("invalid redis key prefix")
)
View Source
var DefPostgresOpts = PostgresOpts{
	Host: "127.0.0.1",
	Port: "5432",
	DB:   "postgres",
	User: "postgres",
}
View Source
var DefRedisOpts = RedisOpts{
	Host:   "127.0.0.1",
	Port:   "6379",
	DB:     0,
	Prefix: "synlock",
}
View Source
var (
	ErrPostgresInvalidAddr = errors.New("invalid postgres address")
)

Functions

This section is empty.

Types

type Mutex

type Mutex interface {
	Lock() error
	Unlock() error
}

type Option added in v0.0.3

type Option func(*options)

func WithErrorHandler added in v0.0.3

func WithErrorHandler(h func(key string, err error)) Option

type Postgres added in v0.0.2

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

func NewPostgres added in v0.0.2

func NewPostgres(conf PostgresOpts) (_ *Postgres, err error)

func (*Postgres) NewMutex added in v0.0.2

func (r *Postgres) NewMutex(key int64) (Mutex, error)

type PostgresMutex added in v0.0.2

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

func (*PostgresMutex) Lock added in v0.0.2

func (s *PostgresMutex) Lock() error

func (*PostgresMutex) Unlock added in v0.0.2

func (s *PostgresMutex) Unlock() error

type PostgresOpts added in v0.0.2

type PostgresOpts struct {
	Host           string
	Port           string
	DB             string
	User           string
	Pass           string
	MaxConnections int
}

type Redis

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

func NewRedis

func NewRedis(conf RedisOpts, opts ...Option) (*Redis, error)

func (*Redis) NewMutex

func (r *Redis) NewMutex(key int64) (Mutex, error)

type RedisMutex

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

func MustRedisMutex added in v0.0.2

func MustRedisMutex(mu Mutex) *RedisMutex

func (*RedisMutex) Lock

func (s *RedisMutex) Lock() (err error)

func (*RedisMutex) LockContext added in v0.0.2

func (s *RedisMutex) LockContext(ctx context.Context) (err error)

func (*RedisMutex) Unlock

func (s *RedisMutex) Unlock() error

type RedisOpts

type RedisOpts struct {
	Host, Port         string
	DB                 int
	Username, Password string
	TLSConfig          *tls.Config
	Prefix             string
}

type Synlock

type Synlock interface {
	NewMutex(key int64) (Mutex, error)
}

func New

func New(conn string) (Synlock, error)

Jump to

Keyboard shortcuts

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