redisdl

package module
v0.0.0-...-1737721 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 7 Imported by: 0

README

redisdl

Build Status Go Report Card Coverage Status

Implementation of distributed locking over Redis

Example

package main

import (
	"context"

	"github.com/go-redis/redis"
	"github.com/saromanov/redisdl"
)

func main() {
	client := redis.NewClient(&redis.Options{
		Network: "tcp",
		Addr:    "127.0.0.1:6379",
	})
	defer client.Close()
	dl, err := redisdl.New(&redisdl.Options{
		Client:     client,
		Key:        "fun.lock",
		RetryCount: 3,
	})
	if err != nil {
		panic(err)
	}
	dl.Lock(context.Background())
	defer dl.Unlock()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	LockTimeout time.Duration
	Key         string
	RetryCount  uint
	Client      *redis.Client
}

Options defines struct with options to the app

type RedisDL

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

RedisDL defines main struct of the app

func New

func New(opt *Options) (*RedisDL, error)

New creates a new app

func (*RedisDL) GetToken

func (r *RedisDL) GetToken() string

GetToken returns currrent token

func (*RedisDL) Lock

func (r *RedisDL) Lock(ctx context.Context) error

Lock provides distributed locking

func (*RedisDL) Unlock

func (r *RedisDL) Unlock() error

Unlock provides unlocking of the store

Jump to

Keyboard shortcuts

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