diff options
| author | alex <[email protected]> | 2026-07-10 20:24:59 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-10 20:24:59 +0200 |
| commit | 36d70e64340033f1e5b928524436c0b2f44c831e (patch) | |
| tree | acbfc67b411f184f2de14a24838aaf1d547b7d91 /pubsub.go | |
| parent | d1628cb76ac4f907d8e57346809e3ac0b8e12de5 (diff) | |
| download | redis-clone-36d70e64340033f1e5b928524436c0b2f44c831e.tar.xz redis-clone-36d70e64340033f1e5b928524436c0b2f44c831e.zip | |
moved commands and database and main into separate packages
Diffstat (limited to 'pubsub.go')
| -rw-r--r-- | pubsub.go | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -3,6 +3,7 @@ package main import ( "errors" "net" + "redisClone/pkg/core" "sync" ) @@ -13,7 +14,7 @@ type Hub struct { func handleSubscribe(conn net.Conn, args []string) { if len(args) < 2 { - conn.Write(serializeRESP(errors.New("wrong number of arguments for 'SUBSCRIBE'"))) + conn.Write(core.SerializeRESP(errors.New("wrong number of arguments for 'SUBSCRIBE'"))) return } channels := args[1:] @@ -32,7 +33,7 @@ func handleSubscribe(conn net.Conn, args []string) { } } - conn.Write(serializeRESP([]any{"subscribe", channel, subCount})) + conn.Write(core.SerializeRESP([]any{"subscribe", channel, subCount})) } } @@ -66,16 +67,16 @@ func handleUnsubscribe(conn net.Conn, args []string) { } } - conn.Write(serializeRESP([]any{"unsubscribe", channel, subCount})) + conn.Write(core.SerializeRESP([]any{"unsubscribe", channel, subCount})) } } func handlePublish(conn net.Conn, args []string) { if len(args) != 3 { - conn.Write(serializeRESP(errors.New("wrong number of arguments for 'PUBLISH'"))) + conn.Write(core.SerializeRESP(errors.New("wrong number of arguments for 'PUBLISH'"))) return } - conn.Write(serializeRESP(hub.Publish(args[1], args[2]))) + conn.Write(core.SerializeRESP(hub.Publish(args[1], args[2]))) } func handleDisconnect(conn net.Conn) { @@ -103,7 +104,7 @@ func (hub *Hub) Publish(channel, message string) int { } hub.mu.RUnlock() - payload := serializeRESP([]string{"message", channel, message}) + payload := core.SerializeRESP([]string{"message", channel, message}) count := 0 for _, conn := range conns { _, err := conn.Write(payload) |
