mirror of
https://github.com/EchoVault/SugarDB.git
synced 2025-11-03 10:21:00 +08:00
RENAMENX Command Implementation (#149)
* Implemented of RENAMENX command - @DMcP89 --------- Co-authored-by: Kelvin Clement Mwinuka <kelvinmwinuka@hotmail.co.uk>
This commit is contained in:
@@ -677,6 +677,21 @@ func handleRename(params internal.HandlerFuncParams) ([]byte, error) {
|
||||
return []byte("+OK\r\n"), nil
|
||||
}
|
||||
|
||||
func handleRenamenx(params internal.HandlerFuncParams) ([]byte, error) {
|
||||
if len(params.Command) != 3 {
|
||||
return nil, errors.New(constants.WrongArgsResponse)
|
||||
}
|
||||
|
||||
newKey := params.Command[2]
|
||||
|
||||
keyExistsCheck := params.KeysExist(params.Context, []string{newKey})
|
||||
if keyExistsCheck[newKey] {
|
||||
return nil, errors.New("Key already exists!")
|
||||
}
|
||||
|
||||
return handleRename(params)
|
||||
}
|
||||
|
||||
func handleFlush(params internal.HandlerFuncParams) ([]byte, error) {
|
||||
if len(params.Command) != 1 {
|
||||
return nil, errors.New(constants.WrongArgsResponse)
|
||||
@@ -1325,5 +1340,14 @@ The REPLACE option removes the destination key before copying the value to it.`,
|
||||
KeyExtractionFunc: moveKeyFunc,
|
||||
HandlerFunc: handleMove,
|
||||
},
|
||||
{
|
||||
Command: "renamenx",
|
||||
Module: constants.GenericModule,
|
||||
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
|
||||
Description: "(RENAMENX key newkey) Renames the specified key with the new name only if the new name does not already exist.",
|
||||
Sync: true,
|
||||
KeyExtractionFunc: renamenxKeyFunc,
|
||||
HandlerFunc: handleRenamenx,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user