Skip to content

Commit

Permalink
Merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
edlng committed Jan 20, 2025
2 parents ae19c82 + b95fbbd commit 6f6ca12
Show file tree
Hide file tree
Showing 9 changed files with 900 additions and 889 deletions.
892 changes: 571 additions & 321 deletions go/api/base_client.go

Large diffs are not rendered by default.

248 changes: 6 additions & 242 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "github.com/valkey-io/valkey-glide/go/glide/api/options"
//
// [valkey.io]: https://valkey.io/commands/?group=Generic
type GenericBaseCommands interface {

Del(keys []string) (int64, error)

Exists(keys []string) (int64, error)
Expand Down Expand Up @@ -43,97 +42,20 @@ type GenericBaseCommands interface {

Touch(keys []string) (int64, error)

Type(key string) (Result[string], error)
Type(key string) (string, error)

Rename(key string, newKey string) (Result[string], error)
Rename(key string, newKey string) (string, error)

Renamenx(key string, newKey string) (bool, error)

Persist(key string) (bool, error)

// Create a key associated with a value that is obtained by
// deserializing the provided serialized value (obtained via [valkey.io]: Https://valkey.io/commands/dump/).
//
// Parameters:
// key - The key to create.
// ttl - The expiry time (in milliseconds). If 0, the key will persist.
// value - The serialized value to deserialize and assign to key.
//
// Return value:
// Return OK if successfully create a key with a value </code>.
//
// Example:
// result, err := client.Restore("key",ttl, value)
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: OK
//
// [valkey.io]: https://valkey.io/commands/restore/
Restore(key string, ttl int64, value string) (Result[string], error)

// Create a key associated with a value that is obtained by
// deserializing the provided serialized value (obtained via [valkey.io]: Https://valkey.io/commands/dump/).
//
// Parameters:
// key - The key to create.
// ttl - The expiry time (in milliseconds). If 0, the key will persist.
// value - The serialized value to deserialize and assign to key.
// restoreOptions - Set restore options with replace and absolute TTL modifiers, object idletime and frequency
//
// Return value:
// Return OK if successfully create a key with a value.
//
// Example:
// restoreOptions := api.NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(api.FREQ, 10)
// resultRestoreOpt, err := client.RestoreWithOptions(key, ttl, value, restoreOptions)
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: OK
//
// [valkey.io]: https://valkey.io/commands/restore/
RestoreWithOptions(key string, ttl int64, value string, option *RestoreOptions) (Result[string], error)

// Returns the internal encoding for the Valkey object stored at key.
//
// Note:
// When in cluster mode, both key and newkey must map to the same hash slot.
//
// Parameters:
// The key of the object to get the internal encoding of.
//
// Return value:
// If key exists, returns the internal encoding of the object stored at
// key as a String. Otherwise, returns null.
//
// Example:
// result, err := client.ObjectEncoding("mykeyRenamenx")
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: embstr
//
// [valkey.io]: https://valkey.io/commands/object-encoding/
ObjectEncoding(key string) (Result[string], error)

// Serialize the value stored at key in a Valkey-specific format and return it to the user.
//
// Parameters:
// The key to serialize.
//
// Return value:
// The serialized value of the data stored at key
// If key does not exist, null will be returned.
//
// Example:
// result, err := client.Dump([]string{"key"})
// if err != nil {
// // handle error
// }
// fmt.Println(result.Value()) // Output: (Serialized Value)
//
// [valkey.io]: https://valkey.io/commands/dump/
Dump(key string) (Result[string], error)

ObjectFreq(key string) (Result[int64], error)
Expand All @@ -142,173 +64,15 @@ type GenericBaseCommands interface {

ObjectRefCount(key string) (Result[int64], error)

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// To store the result into a new key, see the sortStore function.
//
// Parameters:
// key - The key of the list, set, or sorted set to be sorted.
//
// Return value:
// An Array of sorted elements.
//
// Example:
//
// result, err := client.Sort("key")
// result.Value(): [{1 false} {2 false} {3 false}]
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
Sort(key string) ([]Result[string], error)

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// To store the result into a new key, see the sortStore function.
//
// Note:
// In cluster mode, if `key` 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.
// The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is
// supported since Valkey version 8.0.
//
// Parameters:
// key - The key of the list, set, or sorted set to be sorted.
// sortOptions - The SortOptions type.
//
// Return value:
// An Array of sorted elements.
//
// Example:
//
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
// result, err := client.Sort("key", options)
// result.Value(): [{Object_3 false} {c false} {Object_1 false} {a false} {Object_2 false} {b false}]
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
SortWithOptions(key string, sortOptions *options.SortOptions) ([]Result[string], error)

// Sorts the elements in the list, set, or sorted set at key and stores the result in
// destination. The sort command can be used to sort elements based on
// different criteria, apply transformations on sorted elements, and store the result in a new key.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// To get the sort result without storing it into a key, see the sort or sortReadOnly function.
//
// Note:
// In cluster mode, if `key` and `destination` 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:
// key - The key of the list, set, or sorted set to be sorted.
// destination - The key where the sorted result will be stored.
//
// Return value:
// The number of elements in the sorted key stored at destination.
//
// Example:
//
// result, err := client.SortStore("key","destkey")
// result.Value(): 1
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
SortStore(key string, destination string) (Result[int64], error)

// Sorts the elements in the list, set, or sorted set at key and stores the result in
// destination. The sort command can be used to sort elements based on
// different criteria, apply transformations on sorted elements, and store the result in a new key.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// To get the sort result without storing it into a key, see the sort or sortReadOnly function.
//
// Note:
// In cluster mode, if `key` and `destination` 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.
// The use of SortOptions.byPattern and SortOptions.getPatterns
// in cluster mode is supported since Valkey version 8.0.
//
// Parameters:
// key - The key of the list, set, or sorted set to be sorted.
// destination - The key where the sorted result will be stored.
// sortOptions - The SortOptions type.
//
// Return value:
// The number of elements in the sorted key stored at destination.
//
// Example:
//
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
// result, err := client.SortStore("key","destkey",options)
// result.Value(): 1
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (Result[int64], error)

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sortReadOnly command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// This command is routed depending on the client's ReadFrom strategy.
//
// Parameters:
// key - The key of the list, set, or sorted set to be sorted.
//
// Return value:
// An Array of sorted elements.
//
// Example:
//
// result, err := client.SortReadOnly("key")
// result.Value(): [{1 false} {2 false} {3 false}]
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
SortStore(key string, destination string) (int64, error)

SortStoreWithOptions(key string, destination string, sortOptions *options.SortOptions) (int64, error)

SortReadOnly(key string) ([]Result[string], error)

// Sorts the elements in the list, set, or sorted set at key and returns the result.
// The sort command can be used to sort elements based on different criteria and apply
// transformations on sorted elements.
// This command is routed depending on the client's ReadFrom strategy.
//
// Note:
// In cluster mode, if `key` 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.
// The use of SortOptions.byPattern and SortOptions.getPatterns in cluster mode is
// supported since Valkey version 8.0.
//
// Parameters:
// key - The key of the list, set, or sorted set to be sorted.
// sortOptions - The SortOptions type.
//
// Return value:
// An Array of sorted elements.
//
// Example:
//
// options := api.NewSortOptions().SetByPattern("weight_*").SetIsAlpha(false).AddGetPattern("object_*").AddGetPattern("#")
// result, err := client.SortReadOnly("key", options)
// result.Value(): [{Object_3 false} {c false} {Object_1 false} {a false} {Object_2 false} {b false}]
// result.IsNil(): false
//
// [valkey.io]: https://valkey.io/commands/sort/
SortReadOnlyWithOptions(key string, sortOptions *options.SortOptions) ([]Result[string], error)
}
4 changes: 2 additions & 2 deletions go/api/hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ type HashCommands interface {

HLen(key string) (int64, error)

HVals(key string) ([]Result[string], error)
HVals(key string) ([]string, error)

HExists(key string, field string) (bool, error)

HKeys(key string) ([]Result[string], error)
HKeys(key string) ([]string, error)

HStrLen(key string, field string) (int64, error)

Expand Down
15 changes: 7 additions & 8 deletions go/api/list_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,23 @@ package api
//
// [valkey.io]: https://valkey.io/commands/#list
type ListCommands interface {

LPush(key string, elements []string) (int64, error)

LPop(key string) (Result[string], error)

LPopCount(key string, count int64) ([]Result[string], error)
LPopCount(key string, count int64) ([]string, error)

LPos(key string, element string) (Result[int64], error)

LPosWithOptions(key string, element string, options *LPosOptions) (Result[int64], error)

LPosCount(key string, element string, count int64) ([]Result[int64], error)
LPosCount(key string, element string, count int64) ([]int64, error)

LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]Result[int64], error)
LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]int64, error)

RPush(key string, elements []string) (int64, error)

LRange(key string, start int64, end int64) ([]Result[string], error)
LRange(key string, start int64, end int64) ([]string, error)

LIndex(key string, index int64) (Result[string], error)

Expand All @@ -37,13 +36,13 @@ type ListCommands interface {

RPop(key string) (Result[string], error)

RPopCount(key string, count int64) ([]Result[string], error)
RPopCount(key string, count int64) ([]string, error)

LInsert(key string, insertPosition InsertPosition, pivot string, element string) (int64, error)

BLPop(keys []string, timeoutSecs float64) ([]Result[string], error)
BLPop(keys []string, timeoutSecs float64) ([]string, error)

BRPop(keys []string, timeoutSecs float64) ([]Result[string], error)
BRPop(keys []string, timeoutSecs float64) ([]string, error)

RPushX(key string, elements []string) (int64, error)

Expand Down
40 changes: 40 additions & 0 deletions go/api/options/stream_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,3 +262,43 @@ func (xpo *XPendingOptions) ToArgs() ([]string, error) {

return args, nil
}

// Optional arguments for `XGroupCreate` in [StreamCommands]
type XGroupCreateOptions struct {
mkStream bool
entriesRead int64
}

// Create new empty `XGroupCreateOptions`
func NewXGroupCreateOptions() *XGroupCreateOptions {
return &XGroupCreateOptions{false, -1}
}

// Once set and if the stream doesn't exist, creates a new stream with a length of `0`.
func (xgco *XGroupCreateOptions) SetMakeStream() *XGroupCreateOptions {
xgco.mkStream = true
return xgco
}

// A value representing the number of stream entries already read by the group.
//
// Since Valkey version 7.0.0.
func (xgco *XGroupCreateOptions) SetEntriesRead(entriesRead int64) *XGroupCreateOptions {
xgco.entriesRead = entriesRead
return xgco
}

func (xgco *XGroupCreateOptions) ToArgs() ([]string, error) {
var args []string

// if minIdleTime is set, we need to add an `IDLE` argument along with the minIdleTime
if xgco.mkStream {
args = append(args, "MKSTREAM")
}

if xgco.entriesRead > -1 {
args = append(args, "ENTRIESREAD", utils.IntToString(xgco.entriesRead))
}

return args, nil
}
Loading

0 comments on commit 6f6ca12

Please sign in to comment.