wip: 继续 day2

This commit is contained in:
loveuer
2024-10-24 18:01:44 +08:00
parent f3861184b6
commit a17b9bb16b
14 changed files with 387 additions and 45 deletions

View File

@ -3,6 +3,7 @@ package cache
import (
"context"
"errors"
"github.com/go-redis/redis/v8"
"time"
"uauth/internal/interfaces"
)

View File

@ -5,6 +5,10 @@ import (
"uauth/internal/interfaces"
)
const (
Prefix = "sys:uauth:"
)
var (
Client interfaces.Cacher
)

View File

@ -3,19 +3,19 @@ package cache
import (
"fmt"
"gitea.com/taozitaozi/gredis"
"github.com/go-redis/redis/v8"
"net/url"
"strings"
"uauth/internal/opt"
"uauth/internal/tool"
)
func Init() error {
func Init(uri string) error {
var (
err error
)
strs := strings.Split(opt.Cfg.Cache.Uri, "::")
strs := strings.Split(uri, "::")
switch strs[0] {
case "memory":
@ -32,7 +32,7 @@ func Init() error {
)
if len(strs) != 2 {
return fmt.Errorf("cache.Init: invalid cache uri: %s", opt.Cfg.Cache.Uri)
return fmt.Errorf("cache.Init: invalid cache uri: %s", uri)
}
uri := strs[1]
@ -42,7 +42,7 @@ func Init() error {
}
if ins, err = url.Parse(uri); err != nil {
return fmt.Errorf("cache.Init: url parse cache uri: %s, err: %s", opt.Cfg.Cache.Uri, err.Error())
return fmt.Errorf("cache.Init: url parse cache uri: %s, err: %s", uri, err.Error())
}
addr := ins.Host