From 1a7df89c47848b3649512e2236cbe6e995914ae3 Mon Sep 17 00:00:00 2001 From: mountain Date: Sun, 6 Aug 2023 12:41:47 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20count=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wshandler/room.go | 7 +------ wshandler/wshandler.go | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/wshandler/room.go b/wshandler/room.go index 9706e93..c26bbf0 100644 --- a/wshandler/room.go +++ b/wshandler/room.go @@ -5,7 +5,6 @@ import ( "context" "encoding/json" - "github.com/go-redis/redis/v8" "github.com/gorilla/websocket" "repositories.action2quare.com/ayo/gocommon/logger" ) @@ -17,11 +16,10 @@ type room struct { name string destroyChan chan<- string sendMsgChan chan<- send_msg_queue_elem - redisClient *redis.Client } // 만약 destroyChan가 nil이면 room이 비어도 파괴되지 않는다. 영구 유지되는 room -func makeRoom(name string, redisClient *redis.Client, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room { +func makeRoom(name string, destroyChan chan<- string, sendMsgChan chan<- send_msg_queue_elem) *room { return &room{ inChan: make(chan *wsconn, 10), outChan: make(chan *wsconn, 10), @@ -29,7 +27,6 @@ func makeRoom(name string, redisClient *redis.Client, destroyChan chan<- string, name: name, destroyChan: destroyChan, sendMsgChan: sendMsgChan, - redisClient: redisClient, } } @@ -73,11 +70,9 @@ func (r *room) loop(ctx context.Context, conns *map[string]*wsconn) (normalEnd b return true case conn := <-r.inChan: - r.redisClient.HIncrBy(ctx, r.name, "count", 1).Result() (*conns)[conn.sender.Accid.Hex()] = conn case conn := <-r.outChan: - r.redisClient.HIncrBy(ctx, r.name, "count", -1).Result() delete((*conns), conn.sender.Accid.Hex()) if len(*conns) == 0 && r.destroyChan != nil { r.destroyChan <- r.name diff --git a/wshandler/wshandler.go b/wshandler/wshandler.go index e1598cb..d06d72a 100644 --- a/wshandler/wshandler.go +++ b/wshandler/wshandler.go @@ -362,7 +362,7 @@ func (sh *subhandler) mainLoop(ctx context.Context) { findRoom := func(name string, create bool) *room { room := rooms[name] if room == nil && create { - room = makeRoom(name, sh.redisSync, roomDestroyChan, sh.sendMsgChan) + room = makeRoom(name, roomDestroyChan, sh.sendMsgChan) rooms[name] = room room.start(ctx) go sh.callReceiver.OnRoomCreated(sh.region, name)