package redis

import (
	"os"

	"github.com/redis/rueidis"
	"github.com/redis/rueidis/rueidislock"
)

var Locker *rueidislock.Locker

func InitLocker() error {
	redisAddr := os.Getenv("REDIS_ADDR")
	password := os.Getenv("REDIS_PASSWORD")
	locker, err := rueidislock.NewLocker(rueidislock.LockerOption{
		ClientOption: rueidis.ClientOption{InitAddress: []string{redisAddr}, Password: password},
	})
	if err != nil {
		return err
	}
	Locker = &locker
	return nil
}
func CloseLocker() {
	if Locker != nil {
		(*Locker).Close()
	}
	Locker = nil

}
