interlock

package module
v0.0.0-...-3b4d626 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

Interlock

Build Status Coverage Status Go Report Card

Package implements inter service lock based on different external storages.

Example

package main

import (
  "fmt"
  "log"
  "time"

  "github.com/demdxx/interlock/redislock"
  "github.com/demdxx/interlock"
)

func main() {
  const defaultLifetime = time.Minute
  rlock, err := redislock.NewByURL(`redis://host:3456/1?pool=10&max_retries=2&idle_cons=2`, defaultLifetime)
  if err != nil {
    log.Fatal(err)
  }

  if rlock.TryLock("start") {
    fmt.Println("I'm the first!")
  } else {
    fmt.Println("Someone ran first")
  }
}

TODO

  • Zookeeper
  • Consul
  • Aerospike
  • Memcached
  • Redis

Documentation

Overview

Package interlock defines the interface for cross-service lock

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

type Locker interface {
	TryLock(key interface{}, lifetime ...time.Duration) error
	Unlock(key interface{}) error
	IsLocked(key interface{}) bool
	Expire(key interface{}, lifetime ...time.Duration) error
}

Locker provides simple inter-server locks

func NewDummy

func NewDummy() Locker

NewDummy lock object

Directories

Path Synopsis
Package redislock implements locker based on Redis server
Package redislock implements locker based on Redis server

Jump to

Keyboard shortcuts

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