diff options
| author | alex <[email protected]> | 2026-07-09 20:24:44 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-09 20:24:44 +0200 |
| commit | 8f6257e55c2cb8f4c82fe51fbeaa4a8f66dc30ac (patch) | |
| tree | eaf7b5baca0558ad8408fd4dd24169bd7df348cd /main.go | |
| parent | 5cdb2be53d630906bfdfdb97ade81f7602c9fa45 (diff) | |
| download | redis-clone-8f6257e55c2cb8f4c82fe51fbeaa4a8f66dc30ac.tar.xz redis-clone-8f6257e55c2cb8f4c82fe51fbeaa4a8f66dc30ac.zip | |
basic pubsub system
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) |
