mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat/login crud in users sync with sso
This commit is contained in:
Vendored
+38
@@ -0,0 +1,38 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
)
|
||||
|
||||
var (
|
||||
redisClient *redis.Client
|
||||
mu sync.RWMutex
|
||||
)
|
||||
|
||||
// SetRedis assigns the global redis client used across the application.
|
||||
func SetRedis(client *redis.Client) {
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
redisClient = client
|
||||
}
|
||||
|
||||
// Redis returns the configured redis client. It may be nil if not yet initialised.
|
||||
func Redis() *redis.Client {
|
||||
mu.RLock()
|
||||
defer mu.RUnlock()
|
||||
return redisClient
|
||||
}
|
||||
|
||||
// MustRedis returns the redis client or panics if it has not been set.
|
||||
func MustRedis() *redis.Client {
|
||||
mu.RLock()
|
||||
client := redisClient
|
||||
mu.RUnlock()
|
||||
if client == nil {
|
||||
panic(errors.New("redis client not initialised"))
|
||||
}
|
||||
return client
|
||||
}
|
||||
Reference in New Issue
Block a user