feat: INCR command added

This commit is contained in:
Sahil
2024-06-20 01:10:58 +05:30
parent 75baaa5c47
commit 1e0625f28f
5 changed files with 93 additions and 13 deletions

View File

@@ -15,9 +15,10 @@
package echovault
import (
"github.com/echovault/echovault/internal"
"strconv"
"strings"
"github.com/echovault/echovault/internal"
)
// SetOptions modifies the behaviour for the Set command
@@ -416,3 +417,17 @@ func (server *EchoVault) PExpireAt(key string, unixMilliseconds int, options PEx
return internal.ParseIntegerResponse(b)
}
func (server *EchoVault) Incr(key string) (int, error) {
// Construct the command
cmd := []string{"INCR", key}
// Execute the command
b, err := server.handleCommand(server.context, internal.EncodeCommand(cmd), nil, false, true)
if err != nil {
return 0, err
}
// Parse the integer response
return internal.ParseIntegerResponse(b)
}