From fe9efa90f86c88f38fdb15ae1a9dc309662c69f6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 26 Aug 2024 10:26:24 -0700 Subject: [PATCH] finish the global lock init --- modules/globallock/globallock.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/globallock/globallock.go b/modules/globallock/globallock.go index 707d169f05..5f69b5bf12 100644 --- a/modules/globallock/globallock.go +++ b/modules/globallock/globallock.go @@ -6,14 +6,22 @@ package globallock import ( "context" "sync" + + "code.gitea.io/gitea/modules/setting" ) var ( defaultLocker Locker initOnce sync.Once initFunc = func() { - // TODO: read the setting and initialize the default locker. - // Before implementing this, don't use it. + switch setting.GlobalLock.ServiceType { + case "redis": + defaultLocker = NewRedisLocker(setting.GlobalLock.ServiceConnStr) + case "memory": + fallthrough + default: + defaultLocker = NewMemoryLocker() + } } // define initFunc as a variable to make it possible to change it in tests )