diff options
| author | alex <[email protected]> | 2026-07-08 21:04:46 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-08 21:04:46 +0200 |
| commit | aac1dd50b61090461cefc0263f065140be4bf50b (patch) | |
| tree | 9bdb01936379a83c5a5651c7713e55c5c95c3972 /handlers.go | |
| parent | 2d2b8102ecc5b6a786a97c6c0fc49737c9088e63 (diff) | |
| download | redis-clone-aac1dd50b61090461cefc0263f065140be4bf50b.tar.xz redis-clone-aac1dd50b61090461cefc0263f065140be4bf50b.zip | |
added ExecuteMulti method and refactored del to work with shards
Diffstat (limited to 'handlers.go')
| -rw-r--r-- | handlers.go | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/handlers.go b/handlers.go index 1a04db9..980e805 100644 --- a/handlers.go +++ b/handlers.go @@ -74,28 +74,31 @@ func handleSet(conn net.Conn, args []string) { conn.Write(serializeRESP(result)) } -/* + func handleDel(conn net.Conn, args []string) { - db.mu.Lock() - defer db.mu.Unlock() if len(args) < 2 { err := errors.New("wrong number of arguments for 'DEL'") conn.Write(serializeRESP(err)) return } - - deletedKeys := 0 - for i := 1; i<len(args);i++{ - _, exists := db.data[args[i]] - if exists { - delete(db.data, args[i]) - deletedKeys += 1 - } - } + keys := args[:1] + deletedKeys := db.ExecuteMulti(keys, func(shards []*Shard) interface{}{ + count := 0 + for _, key := range keys{ + shard := db.getShard(key) + _, exists := shard.data[key] + if exists { + delete(shard.data, key) + count += 1 + } + } + return count + }) conn.Write(serializeRESP(deletedKeys)) } +/* func handleIncr(conn net.Conn, args []string) { db.mu.Lock() defer db.mu.Unlock() |
