2025-05-10 16:59:41 +08:00
|
|
|
package globals
|
2025-03-18 17:57:07 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
2025-03-26 14:57:44 +08:00
|
|
|
"platform/pkg/env"
|
2025-03-18 17:57:07 +08:00
|
|
|
|
|
|
|
|
"github.com/redis/go-redis/v9"
|
|
|
|
|
)
|
|
|
|
|
|
2025-05-10 16:59:41 +08:00
|
|
|
var Redis *redis.Client
|
2025-03-18 17:57:07 +08:00
|
|
|
|
2025-05-10 16:59:41 +08:00
|
|
|
func initRedis() {
|
|
|
|
|
Redis = redis.NewClient(&redis.Options{
|
2025-03-18 17:57:07 +08:00
|
|
|
Addr: net.JoinHostPort(env.RedisHost, env.RedisPort),
|
|
|
|
|
DB: env.RedisDb,
|
|
|
|
|
Password: env.RedisPass,
|
|
|
|
|
})
|
|
|
|
|
}
|
2025-04-01 11:26:37 +08:00
|
|
|
|
2025-05-10 16:59:41 +08:00
|
|
|
func ExitRedis() error {
|
|
|
|
|
if Redis != nil {
|
|
|
|
|
return Redis.Close()
|
2025-04-01 11:26:37 +08:00
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|