From d724cc84fa94ab6cdd3d8bddd3ab08c99d0aef3a Mon Sep 17 00:00:00 2001 From: mountain Date: Tue, 18 Jul 2023 17:38:04 +0900 Subject: [PATCH] =?UTF-8?q?redis=20pubsub=20=EC=B1=84=EB=84=90=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=97=90=20=EB=94=94=EB=B9=84=20=EC=9D=B8=EB=8D=B1?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authcollection.go | 4 +++- rpc/rpc.go | 1 + wshandler/wshandler.go | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/authcollection.go b/authcollection.go index b5ff8ef..c1e688a 100644 --- a/authcollection.go +++ b/authcollection.go @@ -30,7 +30,7 @@ type Authinfo struct { } const ( - sessionSyncChannelName = "session-sync-channel2" + sessionSyncChannelNamePrefix = "session-sync-channel2" ) type AuthinfoCell interface { @@ -99,6 +99,8 @@ func (ac *redisAuthCell) ToBytes() []byte { func newAuthCollectionWithRedis(redisClient *redis.Client, subctx context.Context, maingateURL string, apiToken string) *AuthCollection { sessionTTL := int64(3600) ac := MakeAuthCollection(time.Duration(sessionTTL * int64(time.Second))) + + sessionSyncChannelName := fmt.Sprintf("%s-%d", sessionSyncChannelNamePrefix, redisClient.Options().DB) pubsub := redisClient.Subscribe(subctx, sessionSyncChannelName) ctx, cancel := context.WithCancel(context.TODO()) go func(ctx context.Context, sub *redis.PubSub, authCache *AuthCollection) { diff --git a/rpc/rpc.go b/rpc/rpc.go index 3bcff82..6a62991 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -68,6 +68,7 @@ func Start(ctx context.Context, redisClient *redis.Client) { hash.Write([]byte(inName)) } } + hash.Write([]byte(fmt.Sprintf("%d", redisClient.Options().DB))) } pubsubName := hex.EncodeToString(hash.Sum(nil))[:16] diff --git a/wshandler/wshandler.go b/wshandler/wshandler.go index 646cf0d..b4f4daf 100644 --- a/wshandler/wshandler.go +++ b/wshandler/wshandler.go @@ -177,8 +177,8 @@ func NewWebsocketHandler() (*WebsocketHandler, error) { }() sh := &subhandler{ - redisMsgChanName: fmt.Sprintf("_wsh_msg_%s", region), - redisCmdChanName: fmt.Sprintf("_wsh_cmd_%s", region), + redisMsgChanName: fmt.Sprintf("_wsh_msg_%s_%d", region, redisSync.Options().DB), + redisCmdChanName: fmt.Sprintf("_wsh_cmd_%s_%d", region, redisSync.Options().DB), redisSync: redisSync, connInOutChan: make(chan *wsconn), deliveryChan: make(chan any, 1000),