wshandler에서 authcache제거하고 config 포맷 변경

This commit is contained in:
2023-07-15 17:08:33 +09:00
parent 269fa0f870
commit f0f459332d
5 changed files with 74 additions and 60 deletions

View File

@ -2,7 +2,6 @@ package gocommon
import (
"context"
"net/url"
"os"
"strconv"
@ -19,23 +18,30 @@ func newRedisClient(uri string, dbidxoffset int) *redis.Client {
return redis.NewClient(option)
}
func NewRedisClient(uri string, dbidx int) (*redis.Client, error) {
func NewRedisClient(uri string) (*redis.Client, error) {
if !*devflag {
return newRedisClient(uri, dbidx), nil
return newRedisClient(uri, 0), nil
}
rdb := newRedisClient(uri, 0)
devUrl, _ := url.Parse(uri)
option, err := redis.ParseURL(uri)
if err != nil {
return nil, err
}
zero := option
zero.DB = 0
rdb := redis.NewClient(zero)
defer rdb.Close()
hostname, _ := os.Hostname()
myidx, _ := rdb.HGet(context.Background(), "private_db", hostname).Result()
if len(myidx) > 0 {
devUrl.Path = "/" + myidx
return newRedisClient(devUrl.String(), dbidx), nil
offset, _ := strconv.Atoi(myidx)
option.DB += offset
return redis.NewClient(option), nil
}
alldbs, err := rdb.HGetAll(context.Background(), "private_db").Result()
if err != nil {
rdb.Close()
return nil, err
}
@ -53,6 +59,6 @@ func NewRedisClient(uri string, dbidx int) (*redis.Client, error) {
return nil, err
}
devUrl.Path = "/" + strconv.Itoa(newidx)
return newRedisClient(devUrl.String(), dbidx), nil
option.DB += newidx
return redis.NewClient(option), nil
}