From 513e5e7961ecc9fe8155811d6cbb6a6c77e0638d Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 8 Jul 2026 20:30:16 +0200 Subject: refactored EXISTS,SET,GET to support multiple shards --- main.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 8edf10f..5e56280 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,6 @@ import ( "net" "os" "strings" - "time" ) @@ -18,9 +17,9 @@ type handlerFunc func(net.Conn, []string) var commandRegistry = map[string]handlerFunc{ "GET": handleGet, "SET": handleSet, - "DEL": handleDel, +// "DEL": handleDel, "EXISTS": handleExists, - "INCR": handleIncr, +/* "INCR": handleIncr, "DECR": handleDecr, "PING": handlePing, "FLUSHALL": handleFlushall, @@ -38,12 +37,20 @@ var commandRegistry = map[string]handlerFunc{ "TYPE": handleType, "DBSIZE": handleDbsize, "KEYS": handleKeys, - "LREM": handleLrem, + "LREM": handleLrem,*/ } func main() { - db = RedisDB{data: make(map[string]Item)} + numShards := 16 + shards := make([]*Shard, numShards) + for i := 0; i < numShards; i++ { + shards[i] = &Shard{ + data: make(map[string]Item), + } +} + db = RedisDB{shards: shards} +/* go func() { ticker := time.NewTicker(1 * time.Second) for range ticker.C { @@ -56,7 +63,7 @@ func main() { db.mu.Unlock() } }() - +*/ listener, err := net.Listen("tcp", ":6379") if err != nil { fmt.Println("error starting server: ", err) -- cgit v1.2.3