redislock

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

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

Go to latest
Published: May 11, 2023 License: MIT Imports: 6 Imported by: 0

README

redislock

install

go get github.com/go-co-op/gocron/lockers/redislock

usage

Here is an example usage that would be deployed in multiple instances

package main

import (
	"time"

	"github.com/go-co-op/gocron"
	"github.com/go-co-op/gocron/lockers/redislock"
	"github.com/redis/go-redis/v9"
)

func main() {
	redisOptions := &redis.Options{
		Addr: "localhost:6379",
	}
	redisClient := redis.NewClient(redisOptions)
	locker, err := redislock.NewRedisLocker(redisClient)
	if err != nil {
		// handle the error
	}

	s := gocron.NewScheduler(time.UTC)
	s.WithDistributedLocker(locker)

	_, err = s.Every("1s").Name("unique_name").Do(func() {
		// task to do
	})
	if err != nil {
		// handle the error
	}

	s.StartBlocking()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRedisLocker

func NewRedisLocker(r *redis.Client) (gocron.Locker, error)

NewRedisLocker provides an implementation of the Locker interface using redis for storage.

Types

This section is empty.

Jump to

Keyboard shortcuts

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