mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-10-07 08:50:59 +08:00
feat: added DECRBY command
This commit is contained in:
@@ -461,3 +461,28 @@ func (server *EchoVault) Decr(key string) (int, error) {
|
||||
// Parse the integer response
|
||||
return internal.ParseIntegerResponse(b)
|
||||
}
|
||||
|
||||
// DecrBy decrements the integer value of the specified key by the given increment.
|
||||
// If the key does not exist, it is created with an initial value of 0 before decrementing.
|
||||
// If the value stored at the key is not an integer, an error is returned.
|
||||
//
|
||||
// Parameters:
|
||||
// - `key` (string): The key whose value is to be decremented.
|
||||
// - `increment` (int): The amount by which to decrement the key's value. This can be a positive or negative integer.
|
||||
//
|
||||
// Returns:
|
||||
// - (int): The new value of the key after the decrement operation.
|
||||
|
||||
func (server *EchoVault) DecrBy(key string, value string) (int, error) {
|
||||
// Construct the command
|
||||
cmd := []string{"DECRBY", key, value}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user