Skip to content

Commit

Permalink
Fixed get command not working
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifercr07 committed Sep 28, 2024
1 parent 2d5f0b6 commit 714ed84
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/db/dicedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package db

import (
"context"
"errors"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -60,9 +61,13 @@ func (db *DiceDB) ExecuteCommand(command *cmds.CommandRequest) interface{} {
if command.Args.Key == "" {
return errorResponse("key is required")
}

val, err := db.getKey(command.Args.Key)
if err != nil {
return errorResponse(fmt.Sprintf("error running get command: %v", err))
switch {
case errors.Is(err, dice.Nil):
return errorResponse("key does not exist")
case err != nil:
return errorResponse(fmt.Sprintf("Get failed %v", err))
}

return map[string]string{"value": val}
Expand Down

0 comments on commit 714ed84

Please sign in to comment.