diff options
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -15,16 +15,16 @@ const NumShards = 16 var db RedisDB var hub Hub -type handlerFunc func(net.Conn, []string) +type baseHandlerFunc func([]string)interface{} +type connectionHandlerFunc func(net.Conn, []string) -var commandRegistry = map[string]handlerFunc{ +var baseCommandRegistry = map[string]baseHandlerFunc{ "GET": handleGet, "SET": handleSet, "DEL": handleDel, "EXISTS": handleExists, "INCR": handleIncr, "DECR": handleDecr, - "PING": handlePing, "RENAME": handleRename, "FLUSHALL": handleFlushall, "RPUSH": handleRpush, @@ -42,9 +42,12 @@ var commandRegistry = map[string]handlerFunc{ "DBSIZE": handleDbsize, "KEYS": handleKeys, "LREM": handleLrem, +} +var connectionCommandRegistry = map[string]connectionHandlerFunc{ "SUBSCRIBE": handleSubscribe, "UNSUBSCRIBE": handleUnsubscribe, "PUBLISH": handlePublish, + "PING": handlePing, } func main() { @@ -115,8 +118,8 @@ func handleConnection(conn net.Conn) { command := strings.ToUpper(args[0]) - if handler, ok := commandRegistry[command]; ok { - handler(conn, args) + if handler, ok := baseCommandRegistry[command]; ok { + conn.Write(serializeRESP(handler(args))) } else { conn.Write(serializeRESP(errors.New("unknown command"))) } |
