Added command length tests for INCRBY command. Renamed INCRBY key func. Return WRONG_ARG_RESPONSE from key funcs when commands are not the correct length.

This commit is contained in:
Kelvin Mwinuka
2024-06-25 12:28:23 +08:00
parent 95f7175f8e
commit 5433b88776
4 changed files with 102 additions and 20 deletions

View File

@@ -139,7 +139,7 @@ func expireAtKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
func incrKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
if len(cmd) != 2 {
return internal.KeyExtractionFuncResult{}, errors.New("wrong number of arguments for INCR")
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
}
return internal.KeyExtractionFuncResult{
WriteKeys: cmd[1:2],
@@ -148,13 +148,22 @@ func incrKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
func decrKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
if len(cmd) != 2 {
return internal.KeyExtractionFuncResult{}, errors.New("wrong number of arguments for INCR")
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
}
return internal.KeyExtractionFuncResult{
WriteKeys: cmd[1:2],
}, nil
}
func incrByKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
if len(cmd) != 3 {
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)
}
return internal.KeyExtractionFuncResult{
WriteKeys: []string{cmd[1]},
}, nil
}
func decrByKeyFunc(cmd []string) (internal.KeyExtractionFuncResult, error) {
if len(cmd) != 3 {
return internal.KeyExtractionFuncResult{}, errors.New(constants.WrongArgsResponse)