mortise

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2018 License: MIT Imports: 6 Imported by: 0

README

mortise

a lock service with single node redis and fencing token

Build Status Coverage Status Go Report Card GoDoc

Install
go get -u github.com/FelixSeptem/mortise
Design

文章链接

https://redis.io/topics/distlock http://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html http://antirez.com/news/101

Documentation

Overview

Package mortise implement a lock service based ob redis with fencing guarantee

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrMutexOccupied

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

mutex has been acquired and still not release

func (*ErrMutexOccupied) Error

func (e *ErrMutexOccupied) Error() string

type ErrOutdatedToken

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

fencing token outdated

func (*ErrOutdatedToken) Error

func (e *ErrOutdatedToken) Error() string

type ErrRedis

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

redis internal error

func (*ErrRedis) Error

func (e *ErrRedis) Error() string

type MutexManager

type MutexManager struct {
	Conn redis.Conn
	Name string // shall be genaral unique
	// contains filtered or unexported fields
}

Mutex manager to del with full lock process

func (*MutexManager) CheckCurrentFencingToken

func (m *MutexManager) CheckCurrentFencingToken(key string, givenToken int64) (bool, error)

compare lock token and given token

func (*MutexManager) GetCurrentFencingToken

func (m *MutexManager) GetCurrentFencingToken(key string) (int64, error)

check current fencing token

func (*MutexManager) Lock

func (m *MutexManager) Lock(key string, expiredTime time.Duration) (int64, error)

use fencing token to acquire lock

func (*MutexManager) Unlock

func (m *MutexManager) Unlock(key string, fencingToken int64) error

unlock:get compare and del key

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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