aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/main.go b/main.go
index 84974cd..80b78cb 100644
--- a/main.go
+++ b/main.go
@@ -13,6 +13,7 @@ import (
const NumShards = 16
var db RedisDB
+var hub Hub
type handlerFunc func(net.Conn, []string)
@@ -41,6 +42,9 @@ var commandRegistry = map[string]handlerFunc{
"DBSIZE": handleDbsize,
"KEYS": handleKeys,
"LREM": handleLrem,
+ "SUBSCRIBE": handleSubscribe,
+ "UNSUBSCRIBE": handleUnsubscribe,
+ "PUBLISH": handlePublish,
}
func main() {
@@ -53,6 +57,7 @@ func main() {
}
}
db = RedisDB{shards: shards}
+ hub = Hub{Channels: make(map[string]map[net.Conn]struct{}),}
go func() {
ticker := time.NewTicker(1 * time.Second)
@@ -88,7 +93,10 @@ func main() {
}
func handleConnection(conn net.Conn) {
- defer conn.Close()
+ defer func() {
+ handleDisconnect(conn)
+ conn.Close()
+ }()
fmt.Println("Client connected:", conn.RemoteAddr())
reader := bufio.NewReader(conn)