Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go: Implement Type, Touch and Unlink commands #2756

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,3 +1102,29 @@ func (client *baseClient) PTTL(key string) (Result[int64], error) {

return handleLongResponse(result)
}

func (client *baseClient) Unlink(keys []string) (Result[int64], error) {
result, err := client.executeCommand(C.Unlink, keys)
if err != nil {
return CreateNilInt64Result(), err
}

return handleLongResponse(result)
}

func (client *baseClient) Type(key string) (Result[string], error) {
result, err := client.executeCommand(C.Type, []string{key})
if err != nil {
return CreateNilStringResult(), err
}
return handleStringOrNullResponse(result)
}

func (client *baseClient) Touch(keys []string) (Result[int64], error) {
result, err := client.executeCommand(C.Touch, keys)
if err != nil {
return CreateNilInt64Result(), err
}

return handleLongResponse(result)
}
72 changes: 72 additions & 0 deletions go/api/generic_commands.go
Yury-Fridlyand marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -313,4 +313,76 @@ type GenericBaseCommands interface {
//
// [valkey.io]: https://valkey.io/commands/pttl/
PTTL(key string) (Result[int64], error)

// Unlink (delete) multiple keys from the database. A key is ignored if it does not exist.
// This command, similar to Del However, this command does not block the server
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
//
// Note:
// In cluster mode, if keys in keys map to different hash slots, the command
// will be split across these slots and executed separately for each. This means the command
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
// call will return the first encountered error, even though some requests may have succeeded
// while others did not. If this behavior impacts your application logic, consider splitting
// the request into sub-requests per slot to ensure atomicity.
//
// Parameters:
// keys - One or more keys to unlink.
//
// Return value:
// Return the number of keys that were unlinked.
//
// Example:
// result, err := client.Unlink([]string{"key1", "key2", "key3"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: int
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
//
// [valkey.io]: Https://valkey.io/commands/unlink/
Unlink(keys []string) (Result[int64], error)

// Alters the last access time of a key(s). A key is ignored if it does not exist.
//
// Note:
// In cluster mode, if keys in keys map to different hash slots, the command
// will be split across these slots and executed separately for each. This means the command
// is atomic only at the slot level. If one or more slot-specific requests fail, the entire
// call will return the first encountered error, even though some requests may have succeeded
// while others did not. If this behavior impacts your application logic, consider splitting
// the request into sub-requests per slot to ensure atomicity.
//
// Parameters:
// The keys to update last access time.
//
// Return value:
// The number of keys that were updated.
//
// Example:
// result, err := client.Touch([]string{"key1", "key2", "key3"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: int
EdricCua marked this conversation as resolved.
Show resolved Hide resolved
//
// [valkey.io]: Https://valkey.io/commands/touch/
Touch(keys []string) (Result[int64], error)

// Type returns the string representation of the type of the value stored at key.
// The different types that can be returned are: string, list, set, zset, hash and stream.
//
// Parameters:
// key - string
//
// Return value:
// If the key exists, the type of the stored value is returned. Otherwise, a none" string is returned.
//
// Example:
// result, err := client.Type([]string{"key"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: string
//
// [valkey.io]: Https://valkey.io/commands/type/
Type(key string) (Result[string], error)
}
Loading
Loading