Skip to content

Commit

Permalink
Added godoc comment for Decr embedded API method.
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinmwinuka committed Jun 23, 2024
1 parent 10f01c1 commit 8ad2714
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
8 changes: 8 additions & 0 deletions echovault/api_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ func (server *EchoVault) Incr(key string) (int, error) {
return internal.ParseIntegerResponse(b)
}

// Decr decrements the value at the given key if it's an integer.
// If the key does not exist, it's created with an initial value of 0 before incrementing.
//
// Parameters:
//
// `key` - string
//
// Returns: The new value as an integer.
func (server *EchoVault) Decr(key string) (int, error) {
// Construct the command
cmd := []string{"DECR", key}
Expand Down
23 changes: 15 additions & 8 deletions internal/modules/generic/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,19 +646,26 @@ LT - Only set the expiry time if the new expiry time is less than the current on
HandlerFunc: handleExpireAt,
},
{
Command: "incr",
Module: constants.GenericModule,
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
Description: `(INCR key) Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that cannot be represented as integer. This operation is limited to 64 bit signed integers.`,
Command: "incr",
Module: constants.GenericModule,
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
Description: `(INCR key)
Increments the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation.
An error is returned if the key contains a value of the wrong type or contains a string that cannot be represented as integer.
This operation is limited to 64 bit signed integers.`,
Sync: true,
KeyExtractionFunc: incrKeyFunc,
HandlerFunc: handleIncr,
},
{
Command: "decr",
Module: constants.GenericModule,
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
Description: `(DECR key) Decrements the number stored at key by one. If the key does not exist, it is set to 0 before performing the operation. An error is returned if the key contains a value of the wrong type or contains a string that cannot be represented as integer. This operation is limited to 64 bit signed integers.`,
Command: "decr",
Module: constants.GenericModule,
Categories: []string{constants.KeyspaceCategory, constants.WriteCategory, constants.FastCategory},
Description: `(DECR key)
Decrements the number stored at key by one.
If the key does not exist, it is set to 0 before performing the operation.
An error is returned if the key contains a value of the wrong type or contains a string that cannot be represented as integer.
This operation is limited to 64 bit signed integers.`,
Sync: true,
KeyExtractionFunc: decrKeyFunc,
HandlerFunc: handleDecr,
Expand Down

0 comments on commit 8ad2714

Please sign in to comment.