mirror of
https://github.com/keven1024/015.git
synced 2026-05-26 15:13:30 +00:00
34 lines
497 B
Go
34 lines
497 B
Go
package utils
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"github.com/redis/rueidis"
|
|
)
|
|
|
|
var (
|
|
rdb rueidis.Client
|
|
ctx = context.Background()
|
|
onceRedis sync.Once
|
|
)
|
|
|
|
func InitRedis() rueidis.Client {
|
|
opt, err := rueidis.ParseURL(GetEnv("redis.url"))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
client, err := rueidis.NewClient(opt)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return client
|
|
}
|
|
|
|
func GetRedisClient() (rueidis.Client, context.Context) {
|
|
onceRedis.Do(func() {
|
|
rdb = InitRedis()
|
|
})
|
|
return rdb, ctx
|
|
}
|