temp
This commit is contained in:
@@ -1,30 +1,29 @@
|
||||
package redis
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/redis/rueidis"
|
||||
"github.com/redis/rueidis/rueidislock"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var Locker *rueidislock.Locker
|
||||
|
||||
func InitLocker() error {
|
||||
func NewRedisLocker(lc fx.Lifecycle) (rueidislock.Locker, 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
|
||||
return nil, err
|
||||
}
|
||||
Locker = &locker
|
||||
return nil
|
||||
}
|
||||
func CloseLocker() {
|
||||
if Locker != nil {
|
||||
(*Locker).Close()
|
||||
}
|
||||
Locker = nil
|
||||
lc.Append(fx.Hook{
|
||||
OnStop: func(_ context.Context) error {
|
||||
locker.Close()
|
||||
|
||||
return nil
|
||||
},
|
||||
})
|
||||
return locker, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user