locker.go 698 B

1234567891011121314151617181920212223242526272829303132333435
  1. package config
  2. import (
  3. "github.com/go-redis/redis/v7"
  4. "gogs.baozhida.cn/zoie/OAuth-core/storage"
  5. "gogs.baozhida.cn/zoie/OAuth-core/storage/locker"
  6. )
  7. var LockerConfig = new(Locker)
  8. type Locker struct {
  9. Redis *RedisConnectOptions
  10. }
  11. // Empty 空设置
  12. func (e Locker) Empty() bool {
  13. return e.Redis == nil
  14. }
  15. // Setup 启用顺序 redis > 其他 > memory
  16. func (e Locker) Setup() (storage.AdapterLocker, error) {
  17. if e.Redis != nil {
  18. client := GetRedisClient()
  19. if client == nil {
  20. options, err := e.Redis.GetRedisOptions()
  21. if err != nil {
  22. return nil, err
  23. }
  24. client = redis.NewClient(options)
  25. _redis = client
  26. }
  27. return locker.NewRedis(client), nil
  28. }
  29. return nil, nil
  30. }