synlock

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: MIT Imports: 13 Imported by: 0

README

Synlock Build 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")
	ErrMaxTryGetLock        = errors.New("all try get lock is failed")
)
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 Postgres

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

func NewPostgres

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

func (*Postgres) NewMutex

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

type PostgresMutex

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

func (*PostgresMutex) Lock

func (s *PostgresMutex) Lock() error

func (*PostgresMutex) Unlock

func (s *PostgresMutex) Unlock() error

type PostgresOpts

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) (*Redis, error)

func (*Redis) NewMutex

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

type RedisMutex

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

func (*RedisMutex) Lock

func (s *RedisMutex) Lock() error

func (*RedisMutex) Unlock

func (s *RedisMutex) Unlock() error

type RedisOpts

type RedisOpts struct {
	Host   string
	Port   string
	DB     int
	Prefix string
}

type Synlock

type Synlock interface {
	NewMutex(key int64, tryCount int) (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