diff --git a/go/api/base_client.go b/go/api/base_client.go index d7e156ff7e..984d5d9120 100644 --- a/go/api/base_client.go +++ b/go/api/base_client.go @@ -232,8 +232,8 @@ func (client *baseClient) Set(key string, value string) (string, error) { // If SetOptions.returnOldValue is set, return the old value as a String. // // [valkey.io]: https://valkey.io/commands/set/ -func (client *baseClient) SetWithOptions(key string, value string, options *SetOptions) (Result[string], error) { - optionArgs, err := options.toArgs() +func (client *baseClient) SetWithOptions(key string, value string, options *options.SetOptions) (Result[string], error) { + optionArgs, err := options.ToArgs() if err != nil { return CreateNilStringResult(), err } @@ -299,15 +299,15 @@ func (client *baseClient) GetEx(key string) (Result[string], error) { // Parameters: // // key - The key to be retrieved from the database. -// options - The [api.GetExOptions]. +// options - The [options.GetExOptions]. // // Return value: // // If key exists, returns the value of key as a Result[string]. Otherwise, return [api.CreateNilStringResult()]. // // [valkey.io]: https://valkey.io/commands/getex/ -func (client *baseClient) GetExWithOptions(key string, options *GetExOptions) (Result[string], error) { - optionArgs, err := options.toArgs() +func (client *baseClient) GetExWithOptions(key string, options *options.GetExOptions) (Result[string], error) { + optionArgs, err := options.ToArgs() if err != nil { return CreateNilStringResult(), err } @@ -1028,7 +1028,7 @@ func (client *baseClient) HIncrByFloat(key string, field string, increment float func (client *baseClient) HScan(key string, cursor string) (string, []string, error) { result, err := client.executeCommand(C.HScan, []string{key, cursor}) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -1042,7 +1042,7 @@ func (client *baseClient) HScan(key string, cursor string) (string, []string, er // // key - The key of the hash. // cursor - The cursor that points to the next iteration of results. A value of "0" indicates the start of the search. -// options - The [api.HashScanOptions]. +// options - The [options.HashScanOptions]. // // Return value: // @@ -1060,12 +1060,12 @@ func (client *baseClient) HScanWithOptions( ) (string, []string, error) { optionArgs, err := options.ToArgs() if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } result, err := client.executeCommand(C.HScan, append([]string{key, cursor}, optionArgs...)) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -1147,7 +1147,7 @@ func (client *baseClient) HRandFieldWithCount(key string, count int64) ([]string // // [valkey.io]: https://valkey.io/commands/hrandfield/ func (client *baseClient) HRandFieldWithCountWithValues(key string, count int64) ([][]string, error) { - result, err := client.executeCommand(C.HRandField, []string{key, utils.IntToString(count), options.WithValues}) + result, err := client.executeCommand(C.HRandField, []string{key, utils.IntToString(count), options.WithValuesKeyword}) if err != nil { return nil, err } @@ -1268,8 +1268,12 @@ func (client *baseClient) LPos(key string, element string) (Result[int64], error // The Result[int64] containing the index of element, or [api.CreateNilInt64Result()] if element is not in the list. // // [valkey.io]: https://valkey.io/commands/lpos/ -func (client *baseClient) LPosWithOptions(key string, element string, options *LPosOptions) (Result[int64], error) { - result, err := client.executeCommand(C.LPos, append([]string{key, element}, options.toArgs()...)) +func (client *baseClient) LPosWithOptions(key string, element string, options *options.LPosOptions) (Result[int64], error) { + optionArgs, err := options.ToArgs() + if err != nil { + return CreateNilInt64Result(), err + } + result, err := client.executeCommand(C.LPos, append([]string{key, element}, optionArgs...)) if err != nil { return CreateNilInt64Result(), err } @@ -1293,7 +1297,7 @@ func (client *baseClient) LPosWithOptions(key string, element string, options *L // // [valkey.io]: https://valkey.io/commands/lpos/ func (client *baseClient) LPosCount(key string, element string, count int64) ([]int64, error) { - result, err := client.executeCommand(C.LPos, []string{key, element, CountKeyword, utils.IntToString(count)}) + result, err := client.executeCommand(C.LPos, []string{key, element, options.CountKeyword, utils.IntToString(count)}) if err != nil { return nil, err } @@ -1311,7 +1315,7 @@ func (client *baseClient) LPosCount(key string, element string, count int64) ([] // key - The name of the list. // element - The value to search for within the list. // count - The number of matches wanted. -// options - The LPos options. +// opts - The LPos options. // // Return value: // @@ -1322,11 +1326,15 @@ func (client *baseClient) LPosCountWithOptions( key string, element string, count int64, - options *LPosOptions, + opts *options.LPosOptions, ) ([]int64, error) { + optionArgs, err := opts.ToArgs() + if err != nil { + return nil, err + } result, err := client.executeCommand( C.LPos, - append([]string{key, element, CountKeyword, utils.IntToString(count)}, options.toArgs()...), + append([]string{key, element, options.CountKeyword, utils.IntToString(count)}, optionArgs...), ) if err != nil { return nil, err @@ -1650,7 +1658,11 @@ func (client *baseClient) SInterCard(keys []string) (int64, error) { // // [valkey.io]: https://valkey.io/commands/sintercard/ func (client *baseClient) SInterCardLimit(keys []string, limit int64) (int64, error) { - args := utils.Concat([]string{utils.IntToString(int64(len(keys)))}, keys, []string{"LIMIT", utils.IntToString(limit)}) + args := utils.Concat( + []string{utils.IntToString(int64(len(keys)))}, + keys, + []string{options.LimitKeyword, utils.IntToString(limit)}, + ) result, err := client.executeCommand(C.SInterCard, args) if err != nil { @@ -1778,7 +1790,7 @@ func (client *baseClient) SUnion(keys []string) (map[string]struct{}, error) { func (client *baseClient) SScan(key string, cursor string) (string, []string, error) { result, err := client.executeCommand(C.SScan, []string{key, cursor}) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -1811,12 +1823,12 @@ func (client *baseClient) SScanWithOptions( ) (string, []string, error) { optionArgs, err := options.ToArgs() if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } result, err := client.executeCommand(C.SScan, append([]string{key, cursor}, optionArgs...)) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -2042,7 +2054,7 @@ func (client *baseClient) RPopCount(key string, count int64) ([]string, error) { // Parameters: // // key - The key of the list. -// insertPosition - The relative position to insert into - either api.Before or api.After the pivot. +// insertPosition - The relative position to insert into - either options.Before or options.After the pivot. // pivot - An element of the list. // element - The new element to insert. // @@ -2055,11 +2067,11 @@ func (client *baseClient) RPopCount(key string, count int64) ([]string, error) { // [valkey.io]: https://valkey.io/commands/linsert/ func (client *baseClient) LInsert( key string, - insertPosition InsertPosition, + insertPosition options.InsertPosition, pivot string, element string, ) (int64, error) { - insertPositionStr, err := insertPosition.toString() + insertPositionStr, err := insertPosition.ToString() if err != nil { return defaultIntResponse, err } @@ -2198,15 +2210,15 @@ func (client *baseClient) LPushX(key string, elements []string) (int64, error) { // Parameters: // // keys - An array of keys to lists. -// listDirection - The direction based on which elements are popped from - see [api.ListDirection]. +// listDirection - The direction based on which elements are popped from - see [options.ListDirection]. // // Return value: // // A map of key name mapped array of popped element. // // [valkey.io]: https://valkey.io/commands/lmpop/ -func (client *baseClient) LMPop(keys []string, listDirection ListDirection) (map[string][]string, error) { - listDirectionStr, err := listDirection.toString() +func (client *baseClient) LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error) { + listDirectionStr, err := listDirection.ToString() if err != nil { return nil, err } @@ -2240,7 +2252,7 @@ func (client *baseClient) LMPop(keys []string, listDirection ListDirection) (map // Parameters: // // keys - An array of keys to lists. -// listDirection - The direction based on which elements are popped from - see [api.ListDirection]. +// listDirection - The direction based on which elements are popped from - see [options.ListDirection]. // count - The maximum number of popped elements. // // Return value: @@ -2250,10 +2262,10 @@ func (client *baseClient) LMPop(keys []string, listDirection ListDirection) (map // [valkey.io]: https://valkey.io/commands/lmpop/ func (client *baseClient) LMPopCount( keys []string, - listDirection ListDirection, + listDirection options.ListDirection, count int64, ) (map[string][]string, error) { - listDirectionStr, err := listDirection.toString() + listDirectionStr, err := listDirection.ToString() if err != nil { return nil, err } @@ -2267,7 +2279,7 @@ func (client *baseClient) LMPopCount( args := make([]string, 0, len(keys)+4) args = append(args, strconv.Itoa(len(keys))) args = append(args, keys...) - args = append(args, listDirectionStr, CountKeyword, utils.IntToString(count)) + args = append(args, listDirectionStr, options.CountKeyword, utils.IntToString(count)) result, err := client.executeCommand(C.LMPop, args) if err != nil { return nil, err @@ -2292,7 +2304,7 @@ func (client *baseClient) LMPopCount( // Parameters: // // keys - An array of keys to lists. -// listDirection - The direction based on which elements are popped from - see [api.ListDirection]. +// listDirection - The direction based on which elements are popped from - see [options.ListDirection]. // timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block indefinitely. // // Return value: @@ -2304,10 +2316,10 @@ func (client *baseClient) LMPopCount( // [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands func (client *baseClient) BLMPop( keys []string, - listDirection ListDirection, + listDirection options.ListDirection, timeoutSecs float64, ) (map[string][]string, error) { - listDirectionStr, err := listDirection.toString() + listDirectionStr, err := listDirection.ToString() if err != nil { return nil, err } @@ -2346,7 +2358,7 @@ func (client *baseClient) BLMPop( // Parameters: // // keys - An array of keys to lists. -// listDirection - The direction based on which elements are popped from - see [api.ListDirection]. +// listDirection - The direction based on which elements are popped from - see [options.ListDirection]. // count - The maximum number of popped elements. // timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of 0 will block // @@ -2361,11 +2373,11 @@ func (client *baseClient) BLMPop( // [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands func (client *baseClient) BLMPopCount( keys []string, - listDirection ListDirection, + listDirection options.ListDirection, count int64, timeoutSecs float64, ) (map[string][]string, error) { - listDirectionStr, err := listDirection.toString() + listDirectionStr, err := listDirection.ToString() if err != nil { return nil, err } @@ -2379,7 +2391,7 @@ func (client *baseClient) BLMPopCount( args := make([]string, 0, len(keys)+5) args = append(args, utils.FloatToString(timeoutSecs), strconv.Itoa(len(keys))) args = append(args, keys...) - args = append(args, listDirectionStr, CountKeyword, utils.IntToString(count)) + args = append(args, listDirectionStr, options.CountKeyword, utils.IntToString(count)) result, err := client.executeCommand(C.BLMPop, args) if err != nil { return nil, err @@ -2435,14 +2447,14 @@ func (client *baseClient) LSet(key string, index int64, element string) (string, func (client *baseClient) LMove( source string, destination string, - whereFrom ListDirection, - whereTo ListDirection, + whereFrom options.ListDirection, + whereTo options.ListDirection, ) (Result[string], error) { - whereFromStr, err := whereFrom.toString() + whereFromStr, err := whereFrom.ToString() if err != nil { return CreateNilStringResult(), err } - whereToStr, err := whereTo.toString() + whereToStr, err := whereTo.ToString() if err != nil { return CreateNilStringResult(), err } @@ -2488,15 +2500,15 @@ func (client *baseClient) LMove( func (client *baseClient) BLMove( source string, destination string, - whereFrom ListDirection, - whereTo ListDirection, + whereFrom options.ListDirection, + whereTo options.ListDirection, timeoutSecs float64, ) (Result[string], error) { - whereFromStr, err := whereFrom.toString() + whereFromStr, err := whereFrom.ToString() if err != nil { return CreateNilStringResult(), err } - whereToStr, err := whereTo.toString() + whereToStr, err := whereTo.ToString() if err != nil { return CreateNilStringResult(), err } @@ -2601,10 +2613,9 @@ func (client *baseClient) Expire(key string, seconds int64) (bool, error) { // The timeout will only be cleared by commands that delete or overwrite the contents of key // // Parameters: -// -// key - The key to expire. -// seconds - Time in seconds for the key to expire -// option - The option to set expiry - NX, XX, GT, LT +// key - The key to expire. +// seconds - Time in seconds for the key to expire. +// option - The option to set expiry, see [options.ExpireCondition]. // // Return value: // @@ -2612,8 +2623,8 @@ func (client *baseClient) Expire(key string, seconds int64) (bool, error) { // or operation skipped due to the provided arguments. // // [valkey.io]: https://valkey.io/commands/expire/ -func (client *baseClient) ExpireWithOptions(key string, seconds int64, expireCondition ExpireCondition) (bool, error) { - expireConditionStr, err := expireCondition.toString() +func (client *baseClient) ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error) { + expireConditionStr, err := expireCondition.ToString() if err != nil { return defaultBoolResponse, err } @@ -2663,10 +2674,9 @@ func (client *baseClient) ExpireAt(key string, unixTimestampInSeconds int64) (bo // The timeout will only be cleared by commands that delete or overwrite the contents of key // // Parameters: -// -// key - The key to expire. -// unixTimestampInSeconds - Absolute Unix timestamp -// option - The option to set expiry - NX, XX, GT, LT +// key - The key to expire. +// unixTimestampInSeconds - Absolute Unix timestamp. +// option - The option to set expiry - see [options.ExpireCondition]. // // Return value: // @@ -2677,9 +2687,9 @@ func (client *baseClient) ExpireAt(key string, unixTimestampInSeconds int64) (bo func (client *baseClient) ExpireAtWithOptions( key string, unixTimestampInSeconds int64, - expireCondition ExpireCondition, + expireCondition options.ExpireCondition, ) (bool, error) { - expireConditionStr, err := expireCondition.toString() + expireConditionStr, err := expireCondition.ToString() if err != nil { return defaultBoolResponse, err } @@ -2723,10 +2733,9 @@ func (client *baseClient) PExpire(key string, milliseconds int64) (bool, error) // The timeout will only be cleared by commands that delete or overwrite the contents of key. // // Parameters: -// -// key - The key to set timeout on it. -// milliseconds - The timeout in milliseconds. -// option - The option to set expiry - NX, XX, GT, LT +// key - The key to set timeout on it. +// milliseconds - The timeout in milliseconds. +// option - The option to set expiry, see [options.ExpireCondition]. // // Return value: // @@ -2737,9 +2746,9 @@ func (client *baseClient) PExpire(key string, milliseconds int64) (bool, error) func (client *baseClient) PExpireWithOptions( key string, milliseconds int64, - expireCondition ExpireCondition, + expireCondition options.ExpireCondition, ) (bool, error) { - expireConditionStr, err := expireCondition.toString() + expireConditionStr, err := expireCondition.ToString() if err != nil { return defaultBoolResponse, err } @@ -2785,10 +2794,9 @@ func (client *baseClient) PExpireAt(key string, unixTimestampInMilliSeconds int6 // The timeout will only be cleared by commands that delete or overwrite the contents of key // // Parameters: -// -// key - The key to set timeout on it. -// unixMilliseconds - The timeout in an absolute Unix timestamp. -// option - The option to set expiry - NX, XX, GT, LT +// key - The key to set timeout on it. +// unixMilliseconds - The timeout in an absolute Unix timestamp. +// option - The option to set expiry, see [options.ExpireCondition]. // // Return value: // @@ -2799,9 +2807,9 @@ func (client *baseClient) PExpireAt(key string, unixTimestampInMilliSeconds int6 func (client *baseClient) PExpireAtWithOptions( key string, unixTimestampInMilliSeconds int64, - expireCondition ExpireCondition, + expireCondition options.ExpireCondition, ) (bool, error) { - expireConditionStr, err := expireCondition.toString() + expireConditionStr, err := expireCondition.ToString() if err != nil { return defaultBoolResponse, err } @@ -3180,7 +3188,7 @@ func (client *baseClient) XRead(keysAndIds map[string]string) (map[string]map[st // Parameters: // // keysAndIds - A map of keys and entry IDs to read from. -// options - Options detailing how to read the stream. +// opts - Options detailing how to read the stream. // // Return value: // A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if @@ -3189,10 +3197,10 @@ func (client *baseClient) XRead(keysAndIds map[string]string) (map[string]map[st // [valkey.io]: https://valkey.io/commands/xread/ func (client *baseClient) XReadWithOptions( keysAndIds map[string]string, - options *options.XReadOptions, + opts *options.XReadOptions, ) (map[string]map[string][][]string, error) { args := make([]string, 0, 5+2*len(keysAndIds)) - optionArgs, _ := options.ToArgs() + optionArgs, _ := opts.ToArgs() args = append(args, optionArgs...) // Note: this loop iterates in an indeterminate order, but it is OK for that case @@ -3202,7 +3210,7 @@ func (client *baseClient) XReadWithOptions( keys = append(keys, key) values = append(values, keysAndIds[key]) } - args = append(args, "STREAMS") + args = append(args, options.StreamsKeyword) args = append(args, keys...) args = append(args, values...) @@ -3254,7 +3262,7 @@ func (client *baseClient) XReadGroup( // group - The consumer group name. // consumer - The group consumer. // keysAndIds - A map of keys and entry IDs to read from. -// options - Options detailing how to read the stream. +// opts - Options detailing how to read the stream. // // Return value: // A `map[string]map[string][][]string` of stream keys to a map of stream entry IDs mapped to an array entries or `nil` if @@ -3265,9 +3273,9 @@ func (client *baseClient) XReadGroupWithOptions( group string, consumer string, keysAndIds map[string]string, - options *options.XReadGroupOptions, + opts *options.XReadGroupOptions, ) (map[string]map[string][][]string, error) { - args, err := createStreamCommandArgs([]string{"GROUP", group, consumer}, keysAndIds, options) + args, err := createStreamCommandArgs([]string{options.GroupKeyword, group, consumer}, keysAndIds, opts) if err != nil { return nil, err } @@ -3284,9 +3292,9 @@ func (client *baseClient) XReadGroupWithOptions( func createStreamCommandArgs( args []string, keysAndIds map[string]string, - options interface{ ToArgs() ([]string, error) }, + opts interface{ ToArgs() ([]string, error) }, ) ([]string, error) { - optionArgs, err := options.ToArgs() + optionArgs, err := opts.ToArgs() if err != nil { return nil, err } @@ -3298,7 +3306,7 @@ func createStreamCommandArgs( keys = append(keys, key) values = append(values, keysAndIds[key]) } - args = append(args, "STREAMS") + args = append(args, options.StreamsKeyword) args = append(args, keys...) args = append(args, values...) return args, nil @@ -3403,7 +3411,7 @@ func (client *baseClient) ZAddIncr( member string, increment float64, ) (Result[float64], error) { - options, err := options.NewZAddOptionsBuilder().SetIncr(true, increment, member) + options, err := options.NewZAddOptions().SetIncr(true, increment, member) if err != nil { return CreateNilFloat64Result(), err } @@ -3666,7 +3674,7 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K // Parameters: // // keys - An array of keys to lists. -// scoreFilter - The element pop criteria - either [api.MIN] or [api.MAX] to pop members with the lowest/highest +// scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest // scores accordingly. // timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block // indefinitely. @@ -3682,10 +3690,10 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K // [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands func (client *baseClient) BZMPop( keys []string, - scoreFilter ScoreFilter, + scoreFilter options.ScoreFilter, timeoutSecs float64, ) (Result[KeyWithArrayOfMembersAndScores], error) { - scoreFilterStr, err := scoreFilter.toString() + scoreFilterStr, err := scoreFilter.ToString() if err != nil { return CreateNilKeyWithArrayOfMembersAndScoresResult(), err } @@ -3726,7 +3734,7 @@ func (client *baseClient) BZMPop( // Parameters: // // keys - An array of keys to lists. -// scoreFilter - The element pop criteria - either [api.MIN] or [api.MAX] to pop members with the lowest/highest +// scoreFilter - The element pop criteria - either [options.MIN] or [options.MAX] to pop members with the lowest/highest // scores accordingly. // count - The maximum number of popped elements. // timeoutSecs - The number of seconds to wait for a blocking operation to complete. A value of `0` will block indefinitely. @@ -3742,11 +3750,11 @@ func (client *baseClient) BZMPop( // [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands func (client *baseClient) BZMPopWithOptions( keys []string, - scoreFilter ScoreFilter, + scoreFilter options.ScoreFilter, timeoutSecs float64, opts *options.ZMPopOptions, ) (Result[KeyWithArrayOfMembersAndScores], error) { - scoreFilterStr, err := scoreFilter.toString() + scoreFilterStr, err := scoreFilter.ToString() if err != nil { return CreateNilKeyWithArrayOfMembersAndScoresResult(), err } @@ -3802,7 +3810,11 @@ func (client *baseClient) BZMPopWithOptions( func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error) { args := make([]string, 0, 10) args = append(args, key) - args = append(args, rangeQuery.ToArgs()...) + queryArgs, err := rangeQuery.ToArgs() + if err != nil { + return nil, err + } + args = append(args, queryArgs...) result, err := client.executeCommand(C.ZRange, args) if err != nil { return nil, err @@ -3835,8 +3847,12 @@ func (client *baseClient) ZRangeWithScores( ) (map[string]float64, error) { args := make([]string, 0, 10) args = append(args, key) - args = append(args, rangeQuery.ToArgs()...) - args = append(args, "WITHSCORES") + queryArgs, err := rangeQuery.ToArgs() + if err != nil { + return nil, err + } + args = append(args, queryArgs...) + args = append(args, options.WithScoresKeyword) result, err := client.executeCommand(C.ZRange, args) if err != nil { return nil, err @@ -3937,7 +3953,7 @@ func (client *baseClient) ZRank(key string, member string) (Result[int64], error // // [valkey.io]: https://valkey.io/commands/zrank/ func (client *baseClient) ZRankWithScore(key string, member string) (Result[int64], Result[float64], error) { - result, err := client.executeCommand(C.ZRank, []string{key, member, options.WithScore}) + result, err := client.executeCommand(C.ZRank, []string{key, member, options.WithScoreKeyword}) if err != nil { return CreateNilInt64Result(), CreateNilFloat64Result(), err } @@ -3990,7 +4006,7 @@ func (client *baseClient) ZRevRank(key string, member string) (Result[int64], er // // [valkey.io]: https://valkey.io/commands/zrevrank/ func (client *baseClient) ZRevRankWithScore(key string, member string) (Result[int64], Result[float64], error) { - result, err := client.executeCommand(C.ZRevRank, []string{key, member, options.WithScore}) + result, err := client.executeCommand(C.ZRevRank, []string{key, member, options.WithScoreKeyword}) if err != nil { return CreateNilInt64Result(), CreateNilFloat64Result(), err } @@ -4187,7 +4203,7 @@ func (client *baseClient) XAutoClaimJustId( // consumer - The group consumer. // minIdleTime - The minimum idle time for the message to be claimed. // start - Filters the claimed entries to those that have an ID equal or greater than the specified value. -// options - Options detailing how to read the stream. +// opts - Options detailing how to read the stream. // // Return value: // @@ -4207,17 +4223,17 @@ func (client *baseClient) XAutoClaimJustIdWithOptions( consumer string, minIdleTime int64, start string, - options *options.XAutoClaimOptions, + opts *options.XAutoClaimOptions, ) (XAutoClaimJustIdResponse, error) { args := []string{key, group, consumer, utils.IntToString(minIdleTime), start} - if options != nil { - optArgs, err := options.ToArgs() + if opts != nil { + optArgs, err := opts.ToArgs() if err != nil { return XAutoClaimJustIdResponse{}, err } args = append(args, optArgs...) } - args = append(args, "JUSTID") + args = append(args, options.JustIdKeyword) result, err := client.executeCommand(C.XAutoClaim, args) if err != nil { return XAutoClaimJustIdResponse{}, err @@ -4293,7 +4309,7 @@ func (client *baseClient) ZScore(key string, member string) (Result[float64], er func (client *baseClient) ZScan(key string, cursor string) (string, []string, error) { result, err := client.executeCommand(C.ZScan, []string{key, cursor}) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -4314,7 +4330,7 @@ func (client *baseClient) ZScan(key string, cursor string) (string, []string, er // returned on the last iteration of the sorted set. // The second return value is always an array of the subset of the sorted set held in `key`. // The array is a flattened series of `string` pairs, where the value is at even indices and the score is at odd indices. -// If `ZScanOptionsBuilder#noScores` is to `true`, the second return value will only contain the members without scores. +// If [ZScanOptions.noScores] is to `true`, the second return value will only contain the members without scores. // // [valkey.io]: https://valkey.io/commands/zscan/ func (client *baseClient) ZScanWithOptions( @@ -4324,12 +4340,12 @@ func (client *baseClient) ZScanWithOptions( ) (string, []string, error) { optionArgs, err := options.ToArgs() if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } result, err := client.executeCommand(C.ZScan, append([]string{key, cursor}, optionArgs...)) if err != nil { - return "", nil, err + return defaultStringResponse, nil, err } return handleScanResponse(result) } @@ -4465,7 +4481,7 @@ func (client *baseClient) XGroupCreateWithOptions( // // [valkey.io]: https://valkey.io/commands/restore/ func (client *baseClient) Restore(key string, ttl int64, value string) (Result[string], error) { - return client.RestoreWithOptions(key, ttl, value, NewRestoreOptionsBuilder()) + return client.RestoreWithOptions(key, ttl, value, options.NewRestoreOptions()) } // Create a key associated with a value that is obtained by @@ -4476,7 +4492,7 @@ func (client *baseClient) Restore(key string, ttl int64, value string) (Result[s // 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 +// restoreOptions - Set restore options with replace and absolute TTL modifiers, object idletime and frequency. // // Return value: // @@ -4484,9 +4500,9 @@ func (client *baseClient) Restore(key string, ttl int64, value string) (Result[s // // [valkey.io]: https://valkey.io/commands/restore/ func (client *baseClient) RestoreWithOptions(key string, ttl int64, - value string, options *RestoreOptions, + value string, options *options.RestoreOptions, ) (Result[string], error) { - optionArgs, err := options.toArgs() + optionArgs, err := options.ToArgs() if err != nil { return CreateNilStringResult(), err } @@ -4508,7 +4524,7 @@ func (client *baseClient) RestoreWithOptions(key string, ttl int64, // // Return value: // -// The serialized value of the data stored at key +// The serialized value of the data stored at key. // If key does not exist, null will be returned. // // [valkey.io]: https://valkey.io/commands/dump/ @@ -4533,7 +4549,7 @@ func (client *baseClient) Dump(key string) (Result[string], error) { // Return value: // // If key exists, returns the internal encoding of the object stored at -// key as a String. Otherwise, returns null. +// key as a String. Otherwise, returns `null`. // // [valkey.io]: https://valkey.io/commands/object-encoding/ func (client *baseClient) ObjectEncoding(key string) (Result[string], error) { @@ -4654,8 +4670,12 @@ func (client *baseClient) XGroupSetIdWithOptions( // // [valkey.io]: https://valkey.io/commands/zremrangebylex/ func (client *baseClient) ZRemRangeByLex(key string, rangeQuery options.RangeByLex) (int64, error) { + queryArgs, err := rangeQuery.ToArgsRemRange() + if err != nil { + return defaultIntResponse, err + } result, err := client.executeCommand( - C.ZRemRangeByLex, append([]string{key}, rangeQuery.ToArgsRemRange()...)) + C.ZRemRangeByLex, append([]string{key}, queryArgs...)) if err != nil { return defaultIntResponse, err } @@ -4682,7 +4702,7 @@ func (client *baseClient) ZRemRangeByLex(key string, rangeQuery options.RangeByL func (client *baseClient) ZRemRangeByRank(key string, start int64, stop int64) (int64, error) { result, err := client.executeCommand(C.ZRemRangeByRank, []string{key, utils.IntToString(start), utils.IntToString(stop)}) if err != nil { - return 0, err + return defaultIntResponse, err } return handleIntResponse(result) } @@ -4705,9 +4725,13 @@ func (client *baseClient) ZRemRangeByRank(key string, start int64, stop int64) ( // // [valkey.io]: https://valkey.io/commands/zremrangebyscore/ func (client *baseClient) ZRemRangeByScore(key string, rangeQuery options.RangeByScore) (int64, error) { - result, err := client.executeCommand(C.ZRemRangeByScore, append([]string{key}, rangeQuery.ToArgsRemRange()...)) + queryArgs, err := rangeQuery.ToArgsRemRange() if err != nil { - return 0, err + return defaultIntResponse, err + } + result, err := client.executeCommand(C.ZRemRangeByScore, append([]string{key}, queryArgs...)) + if err != nil { + return defaultIntResponse, err } return handleIntResponse(result) } @@ -4787,7 +4811,7 @@ func (client *baseClient) ZRandMemberWithCount(key string, count int64) ([]strin // // [valkey.io]: https://valkey.io/commands/zrandmember/ func (client *baseClient) ZRandMemberWithCountWithScores(key string, count int64) ([]MemberAndScore, error) { - result, err := client.executeCommand(C.ZRandMember, []string{key, utils.IntToString(count), options.WithScores}) + result, err := client.executeCommand(C.ZRandMember, []string{key, utils.IntToString(count), options.WithScoresKeyword}) if err != nil { return nil, err } @@ -4932,7 +4956,10 @@ func (client *baseClient) Sort(key string) ([]Result[string], error) { // // [valkey.io]: https://valkey.io/commands/sort/ func (client *baseClient) SortWithOptions(key string, options *options.SortOptions) ([]Result[string], error) { - optionArgs := options.ToArgs() + optionArgs, err := options.ToArgs() + if err != nil { + return nil, err + } result, err := client.executeCommand(C.Sort, append([]string{key}, optionArgs...)) if err != nil { return nil, err @@ -4989,7 +5016,10 @@ func (client *baseClient) SortReadOnly(key string) ([]Result[string], error) { // // [valkey.io]: https://valkey.io/commands/sort_ro/ func (client *baseClient) SortReadOnlyWithOptions(key string, options *options.SortOptions) ([]Result[string], error) { - optionArgs := options.ToArgs() + optionArgs, err := options.ToArgs() + if err != nil { + return nil, err + } result, err := client.executeCommand(C.SortReadOnly, append([]string{key}, optionArgs...)) if err != nil { return nil, err @@ -5024,7 +5054,7 @@ func (client *baseClient) SortReadOnlyWithOptions(key string, options *options.S // // [valkey.io]: https://valkey.io/commands/sort/ func (client *baseClient) SortStore(key string, destination string) (int64, error) { - result, err := client.executeCommand(C.Sort, []string{key, "STORE", destination}) + result, err := client.executeCommand(C.Sort, []string{key, options.StoreKeyword, destination}) if err != nil { return defaultIntResponse, err } @@ -5050,10 +5080,9 @@ func (client *baseClient) SortStore(key string, destination string) (int64, erro // 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. +// key - The key of the list, set, or sorted set to be sorted. +// destination - The key where the sorted result will be stored. +// opts - The [options.SortOptions] type. // // Return value: // @@ -5063,10 +5092,13 @@ func (client *baseClient) SortStore(key string, destination string) (int64, erro func (client *baseClient) SortStoreWithOptions( key string, destination string, - options *options.SortOptions, + opts *options.SortOptions, ) (int64, error) { - optionArgs := options.ToArgs() - result, err := client.executeCommand(C.Sort, append([]string{key, "STORE", destination}, optionArgs...)) + optionArgs, err := opts.ToArgs() + if err != nil { + return defaultIntResponse, err + } + result, err := client.executeCommand(C.Sort, append([]string{key, options.StoreKeyword, destination}, optionArgs...)) if err != nil { return defaultIntResponse, err } @@ -5404,7 +5436,7 @@ func (client *baseClient) XClaimJustIdWithOptions( } args = append(args, optionArgs...) } - args = append(args, options.JUST_ID_VALKEY_API) + args = append(args, options.JustIdKeyword) result, err := client.executeCommand(C.XClaim, args) if err != nil { return nil, err @@ -5459,9 +5491,9 @@ func (client *baseClient) Copy(source string, destination string) (bool, error) func (client *baseClient) CopyWithOptions( source string, destination string, - options *CopyOptions, + options *options.CopyOptions, ) (bool, error) { - optionArgs, err := options.toArgs() + optionArgs, err := options.ToArgs() if err != nil { return defaultBoolResponse, err } @@ -5770,7 +5802,10 @@ func (client *baseClient) Time() ([]string, error) { // // [valkey.io]: https://valkey.io/commands/zinter/ func (client *baseClient) ZInter(keys options.KeyArray) ([]string, error) { - args := keys.ToArgs() + args, err := keys.ToArgs() + if err != nil { + return nil, err + } result, err := client.executeCommand(C.ZInter, args) if err != nil { return nil, err @@ -5802,7 +5837,7 @@ func (client *baseClient) ZInter(keys options.KeyArray) ([]string, error) { // // Example: // -// res, err := client.ZInterWithScores(options.NewZInterOptionsBuilder(options.NewKeyArray("key1", "key2", "key3"))) +// res, err := client.ZInterWithScores(options.NewZInterOptions(options.NewKeyArray("key1", "key2", "key3"))) // fmt.Println(res) // map[member1:1.0 member2:2.0 member3:3.0] // // [valkey.io]: https://valkey.io/commands/zinter/ @@ -5810,13 +5845,16 @@ func (client *baseClient) ZInterWithScores( keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions *options.ZInterOptions, ) (map[string]float64, error) { - args := keysOrWeightedKeys.ToArgs() + args, err := keysOrWeightedKeys.ToArgs() + if err != nil { + return nil, err + } optionsArgs, err := zInterOptions.ToArgs() if err != nil { return nil, err } args = append(args, optionsArgs...) - args = append(args, options.WithScores) + args = append(args, options.WithScoresKeyword) result, err := client.executeCommand(C.ZInter, args) if err != nil { return nil, err @@ -5881,7 +5919,7 @@ func (client *baseClient) ZInterStore(destination string, keysOrWeightedKeys opt // // Example: // -// res, err := client.ZInterStore("destination", options.NewZInterOptionsBuilder(options.NewKeyArray("key1", "key2", "key3"))) +// res, err := client.ZInterStore("destination", options.NewZInterOptions(options.NewKeyArray("key1", "key2", "key3"))) // fmt.Println(res) // 3 // // [valkey.io]: https://valkey.io/commands/zinterstore/ @@ -5890,7 +5928,11 @@ func (client *baseClient) ZInterStoreWithOptions( keysOrWeightedKeys options.KeysOrWeightedKeys, zInterOptions *options.ZInterOptions, ) (int64, error) { - args := append([]string{destination}, keysOrWeightedKeys.ToArgs()...) + args, err := keysOrWeightedKeys.ToArgs() + if err != nil { + return defaultIntResponse, err + } + args = append([]string{destination}, args...) if zInterOptions != nil { optionsArgs, err := zInterOptions.ToArgs() if err != nil { @@ -5972,7 +6014,7 @@ func (client *baseClient) ZDiff(keys []string) ([]string, error) { func (client *baseClient) ZDiffWithScores(keys []string) (map[string]float64, error) { args := append([]string{}, strconv.Itoa(len(keys))) args = append(args, keys...) - result, err := client.executeCommand(C.ZDiff, append(args, options.WithScores)) + result, err := client.executeCommand(C.ZDiff, append(args, options.WithScoresKeyword)) if err != nil { return nil, err } diff --git a/go/api/bitmap_commands_test.go b/go/api/bitmap_commands_test.go index 6d7ebece42..29dedefd5d 100644 --- a/go/api/bitmap_commands_test.go +++ b/go/api/bitmap_commands_test.go @@ -51,7 +51,7 @@ func ExampleGlideClient_BitCount() { func ExampleGlideClient_BitCountWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function - options := options.NewBitCountOptionsBuilder(). + options := options.NewBitCountOptions(). SetStart(1). SetEnd(1). SetBitmapIndexType(options.BYTE) diff --git a/go/api/generic_base_commands.go b/go/api/generic_base_commands.go index 737310328d..738b73aaba 100644 --- a/go/api/generic_base_commands.go +++ b/go/api/generic_base_commands.go @@ -16,19 +16,19 @@ type GenericBaseCommands interface { Expire(key string, seconds int64) (bool, error) - ExpireWithOptions(key string, seconds int64, expireCondition ExpireCondition) (bool, error) + ExpireWithOptions(key string, seconds int64, expireCondition options.ExpireCondition) (bool, error) ExpireAt(key string, unixTimestampInSeconds int64) (bool, error) - ExpireAtWithOptions(key string, unixTimestampInSeconds int64, expireCondition ExpireCondition) (bool, error) + ExpireAtWithOptions(key string, unixTimestampInSeconds int64, expireCondition options.ExpireCondition) (bool, error) PExpire(key string, milliseconds int64) (bool, error) - PExpireWithOptions(key string, milliseconds int64, expireCondition ExpireCondition) (bool, error) + PExpireWithOptions(key string, milliseconds int64, expireCondition options.ExpireCondition) (bool, error) PExpireAt(key string, unixTimestampInMilliSeconds int64) (bool, error) - PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, expireCondition ExpireCondition) (bool, error) + PExpireAtWithOptions(key string, unixTimestampInMilliSeconds int64, expireCondition options.ExpireCondition) (bool, error) ExpireTime(key string) (int64, error) @@ -52,7 +52,7 @@ type GenericBaseCommands interface { Restore(key string, ttl int64, value string) (Result[string], error) - RestoreWithOptions(key string, ttl int64, value string, option *RestoreOptions) (Result[string], error) + RestoreWithOptions(key string, ttl int64, value string, option *options.RestoreOptions) (Result[string], error) ObjectEncoding(key string) (Result[string], error) @@ -80,5 +80,5 @@ type GenericBaseCommands interface { Copy(source string, destination string) (bool, error) - CopyWithOptions(source string, destination string, option *CopyOptions) (bool, error) + CopyWithOptions(source string, destination string, option *options.CopyOptions) (bool, error) } diff --git a/go/api/generic_base_commands_test.go b/go/api/generic_base_commands_test.go index 51517edeb1..518fd4cbba 100644 --- a/go/api/generic_base_commands_test.go +++ b/go/api/generic_base_commands_test.go @@ -120,7 +120,7 @@ func ExampleGlideClusterClient_Expire() { func ExampleGlideClient_ExpireWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.ExpireWithOptions("key", 1, HasNoExpiry) + result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -135,7 +135,7 @@ func ExampleGlideClient_ExpireWithOptions() { func ExampleGlideClusterClient_ExpireWithOptions() { var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.ExpireWithOptions("key", 1, HasNoExpiry) + result1, err := client.ExpireWithOptions("key", 1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -180,7 +180,7 @@ func ExampleGlideClusterClient_ExpireAt() { func ExampleGlideClient_ExpireAtWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, HasNoExpiry) + result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -195,7 +195,7 @@ func ExampleGlideClient_ExpireAtWithOptions() { func ExampleGlideClusterClient_ExpireAtWithOptions() { var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, HasNoExpiry) + result1, err := client.ExpireAtWithOptions("key", time.Now().Unix()+1, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -240,7 +240,7 @@ func ExampleGlideClusterClient_PExpire() { func ExampleGlideClient_PExpireWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.PExpireWithOptions("key", int64(5*1000), HasNoExpiry) + result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -255,7 +255,7 @@ func ExampleGlideClient_PExpireWithOptions() { func ExampleGlideClusterClient_PExpireWithOptions() { var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.PExpireWithOptions("key", int64(5*1000), HasNoExpiry) + result1, err := client.PExpireWithOptions("key", int64(5*1000), options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -300,7 +300,7 @@ func ExampleGlideClusterClient_PExpireAt() { func ExampleGlideClient_PExpireAtWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, HasNoExpiry) + result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -315,7 +315,7 @@ func ExampleGlideClient_PExpireAtWithOptions() { func ExampleGlideClusterClient_PExpireAtWithOptions() { var client *GlideClusterClient = getExampleGlideClusterClient() // example helper function result, err := client.Set("key", "someValue") - result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, HasNoExpiry) + result1, err := client.PExpireAtWithOptions("key", time.Now().Unix()*1000, options.HasNoExpiry) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -696,8 +696,8 @@ func ExampleGlideClient_RestoreWithOptions() { result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) - result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), - NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(FREQ, 10)) + opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10) + result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -716,8 +716,8 @@ func ExampleGlideClusterClient_RestoreWithOptions() { result, err := client.Set("key1", "someValue") dump, err := client.Dump("key1") result1, err := client.Del([]string{"key1"}) - result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), - NewRestoreOptionsBuilder().SetReplace().SetABSTTL().SetEviction(FREQ, 10)) + opts := options.NewRestoreOptions().SetReplace().SetABSTTL().SetEviction(options.FREQ, 10) + result2, err := client.RestoreWithOptions("key1", 0, dump.Value(), opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -1156,7 +1156,7 @@ func ExampleGlideClient_CopyWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function client.Set("key1", "someValue") - opts := NewCopyOptionsBuilder().SetReplace() + opts := options.NewCopyOptions().SetReplace() client.CopyWithOptions("key1", "key2", opts) result, err := client.Get("key2") @@ -1173,7 +1173,7 @@ func ExampleGlideClusterClient_CopyWithOptions() { client.Set("{key}1", "someValue") - opts := NewCopyOptionsBuilder().SetReplace() + opts := options.NewCopyOptions().SetReplace() client.CopyWithOptions("{key}1", "{key}2", opts) result, err := client.Get("{key}2") diff --git a/go/api/glide_client.go b/go/api/glide_client.go index 05140f0ee7..69d2a174db 100644 --- a/go/api/glide_client.go +++ b/go/api/glide_client.go @@ -156,7 +156,7 @@ func (client *GlideClient) Select(index int64) (string, error) { // // [valkey.io]: https://valkey.io/commands/info/ func (client *GlideClient) Info() (string, error) { - return client.InfoWithOptions(InfoOptions{[]Section{}}) + return client.InfoWithOptions(options.InfoOptions{Sections: []options.Section{}}) } // Gets information and statistics about the server. @@ -173,7 +173,7 @@ func (client *GlideClient) Info() (string, error) { // // Example: // -// opts := api.InfoOptions{Sections: []api.Section{api.Server}} +// opts := options.InfoOptions{Sections: []options.Section{options.Server}} // response, err := standaloneClient.InfoWithOptions(opts) // if err != nil { // // handle error @@ -181,8 +181,12 @@ func (client *GlideClient) Info() (string, error) { // fmt.Println(response) // // [valkey.io]: https://valkey.io/commands/info/ -func (client *GlideClient) InfoWithOptions(options InfoOptions) (string, error) { - result, err := client.executeCommand(C.Info, options.toArgs()) +func (client *GlideClient) InfoWithOptions(options options.InfoOptions) (string, error) { + optionArgs, err := options.ToArgs() + if err != nil { + return defaultStringResponse, err + } + result, err := client.executeCommand(C.Info, optionArgs) if err != nil { return defaultStringResponse, err } @@ -261,13 +265,17 @@ func (client *GlideClient) Ping() (string, error) { // // For example: // -// options := options.NewPingOptionsBuilder().SetMessage("hello") +// options := options.NewPingOptions().SetMessage("hello") // result, err := client.PingWithOptions(options) // result: "hello" // // [valkey.io]: https://valkey.io/commands/ping/ func (client *GlideClient) PingWithOptions(pingOptions options.PingOptions) (string, error) { - result, err := client.executeCommand(C.Ping, pingOptions.ToArgs()) + optionArgs, err := pingOptions.ToArgs() + if err != nil { + return defaultStringResponse, err + } + result, err := client.executeCommand(C.Ping, optionArgs) if err != nil { return defaultStringResponse, err } diff --git a/go/api/glide_cluster_client.go b/go/api/glide_cluster_client.go index 9ef021d6f9..70e1240d05 100644 --- a/go/api/glide_cluster_client.go +++ b/go/api/glide_cluster_client.go @@ -131,9 +131,9 @@ func (client *GlideClusterClient) Info() (map[string]string, error) { // // Example: // -// opts := api.ClusterInfoOptions{ -// InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}}, -// Route: api.RandomRoute.ToPtr(), +// opts := options.ClusterInfoOptions{ +// InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Server}}, +// RouteOption: &options.RouteOption{Route: config.RandomRoute}, // } // response, err := clusterClient.InfoWithOptions(opts) // if err != nil { @@ -143,9 +143,13 @@ func (client *GlideClusterClient) Info() (map[string]string, error) { // fmt.Println(response.SingleValue()) // // [valkey.io]: https://valkey.io/commands/info/ -func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (ClusterValue[string], error) { - if options.Route == nil { - response, err := client.executeCommand(C.Info, options.toArgs()) +func (client *GlideClusterClient) InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error) { + optionArgs, err := options.ToArgs() + if err != nil { + return createEmptyClusterValue[string](), err + } + if options.RouteOption == nil || options.RouteOption.Route == nil { + response, err := client.executeCommand(C.Info, optionArgs) if err != nil { return createEmptyClusterValue[string](), err } @@ -155,11 +159,11 @@ func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (C } return createClusterMultiValue[string](data), nil } - response, err := client.executeCommandWithRoute(C.Info, options.toArgs(), *options.Route) + response, err := client.executeCommandWithRoute(C.Info, optionArgs, options.Route) if err != nil { return createEmptyClusterValue[string](), err } - if (*options.Route).IsMultiNode() { + if options.Route.IsMultiNode() { data, err := handleStringToStringMapResponse(response) if err != nil { return createEmptyClusterValue[string](), err @@ -193,7 +197,7 @@ func (client *GlideClusterClient) InfoWithOptions(options ClusterInfoOptions) (C // // route := config.SimpleNodeRoute(config.RandomRoute) // result, err := client.CustomCommandWithRoute([]string{"ping"}, route) -// result.SingleValue().(string): "PONG" +// result.SingleValue().(string): "ping" // // [Valkey GLIDE Wiki]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#custom-command func (client *GlideClusterClient) CustomCommandWithRoute( @@ -237,7 +241,7 @@ func (client *GlideClusterClient) Ping() (string, error) { // // Parameters: // -// pingOptions - The PingOptions type. +// pingOptions - The [ClusterPingOptions] type. // // Return value: // @@ -245,27 +249,26 @@ func (client *GlideClusterClient) Ping() (string, error) { // // For example: // -// route := config.Route(config.RandomRoute) -// opts := options.ClusterPingOptions{ -// PingOptions: &options.PingOptions{ -// Message: "Hello", -// }, -// Route: &route, -// } +// route := options.RouteOption{config.RandomRoute} +// opts := options.ClusterPingOptions{ &options.PingOptions{ "Hello" }, &route } // result, err := clusterClient.PingWithOptions(opts) // fmt.Println(result) // Output: Hello // // [valkey.io]: https://valkey.io/commands/ping/ func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPingOptions) (string, error) { - if pingOptions.Route == nil { - response, err := client.executeCommand(C.Ping, pingOptions.ToArgs()) + args, err := pingOptions.ToArgs() + if err != nil { + return defaultStringResponse, err + } + if pingOptions.RouteOption == nil || pingOptions.RouteOption.Route == nil { + response, err := client.executeCommand(C.Ping, args) if err != nil { return defaultStringResponse, err } return handleStringResponse(response) } - response, err := client.executeCommandWithRoute(C.Ping, pingOptions.ToArgs(), *pingOptions.Route) + response, err := client.executeCommandWithRoute(C.Ping, args, pingOptions.Route) if err != nil { return defaultStringResponse, err } @@ -280,7 +283,7 @@ func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPin // // Parameters: // -// options - The TimeOptions type. +// options - The [RouteOption] type. // // Return value: // @@ -290,11 +293,9 @@ func (client *GlideClusterClient) PingWithOptions(pingOptions options.ClusterPin // // Example: // -// route := config.Route(config.RandomRoute) -// opts := options.ClusterTimeOptions{ -// Route: &route, -// } -// fmt.Println(clusterResponse.SingleValue()) // Output: [1737994354 547816] +// opts := options.RouteOption{config.RandomRoute} +// response := client.TimeWithOptions(opts) +// fmt.Println(response.SingleValue()) // Output: [1737994354 547816] // // [valkey.io]: https://valkey.io/commands/time/ func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (ClusterValue[[]string], error) { @@ -307,15 +308,18 @@ func (client *GlideClusterClient) TimeWithOptions(opts options.RouteOption) (Clu // Returns the number of keys in the database. // +// Parameters: +// +// options - The [RouteOption] type. +// // Return value: // // The number of keys in the database. // // Example: // -// route := api.SimpleNodeRoute(api.RandomRoute) -// options := options.NewDBOptionsBuilder().SetRoute(route) -// result, err := client.DBSizeWithOption(route) +// options := options.RouteOption{config.RandomRoute} +// result, err := client.DBSizeWithOption(options) // if err != nil { // // handle error // } @@ -335,7 +339,7 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i // // Parameters: // -// message - The provided message. +// echoOptions - The [ClusterEchoOptions] type. // // Return value: // @@ -343,7 +347,8 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i // // Example: // -// response, err := clusterClient.EchoWithOptions(opts) +// options := options.ClusterEchoOptions{&options.EchoOptions{"Hi"}, &options.RouteOption{config.AllNodes}} +// response, err := clusterClient.EchoWithOptions(options) // if err != nil { // // handle error // } @@ -353,12 +358,19 @@ func (client *GlideClusterClient) DBSizeWithOptions(opts options.RouteOption) (i // // [valkey.io]: https://valkey.io/commands/echo/ func (client *GlideClusterClient) EchoWithOptions(echoOptions options.ClusterEchoOptions) (ClusterValue[string], error) { - response, err := client.executeCommandWithRoute(C.Echo, echoOptions.ToArgs(), - echoOptions.RouteOption.Route) + args, err := echoOptions.ToArgs() + if err != nil { + return createEmptyClusterValue[string](), err + } + var route config.Route + if echoOptions.RouteOption != nil && echoOptions.RouteOption.Route != nil { + route = echoOptions.RouteOption.Route + } + response, err := client.executeCommandWithRoute(C.Echo, args, route) if err != nil { return createEmptyClusterValue[string](), err } - if echoOptions.RouteOption.Route != nil && + if echoOptions.RouteOption != nil && echoOptions.RouteOption.Route != nil && (echoOptions.RouteOption.Route).IsMultiNode() { data, err := handleStringToStringMapResponse(response) if err != nil { diff --git a/go/api/hash_commands_test.go b/go/api/hash_commands_test.go index 517484db5a..e669bf5b2c 100644 --- a/go/api/hash_commands_test.go +++ b/go/api/hash_commands_test.go @@ -389,7 +389,7 @@ func ExampleGlideClient_HScanWithOptions() { } result, err := client.HSet("my_hash", fields) - opts := options.NewHashScanOptionsBuilder().SetMatch("a") + opts := options.NewHashScanOptions().SetMatch("a") resCursor, resCollection, err := client.HScanWithOptions("my_hash", "0", opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) diff --git a/go/api/list_commands.go b/go/api/list_commands.go index d1f688bb5c..4661cd58b2 100644 --- a/go/api/list_commands.go +++ b/go/api/list_commands.go @@ -2,6 +2,10 @@ package api +import ( + "github.com/valkey-io/valkey-glide/go/api/options" +) + // Supports commands and transactions for the "List" group of commands for standalone and cluster clients. // // See [valkey.io] for details. @@ -16,11 +20,11 @@ type ListCommands interface { LPos(key string, element string) (Result[int64], error) - LPosWithOptions(key string, element string, options *LPosOptions) (Result[int64], error) + LPosWithOptions(key string, element string, options *options.LPosOptions) (Result[int64], error) LPosCount(key string, element string, count int64) ([]int64, error) - LPosCountWithOptions(key string, element string, count int64, options *LPosOptions) ([]int64, error) + LPosCountWithOptions(key string, element string, count int64, options *options.LPosOptions) ([]int64, error) RPush(key string, elements []string) (int64, error) @@ -38,7 +42,7 @@ type ListCommands interface { RPopCount(key string, count int64) ([]string, error) - LInsert(key string, insertPosition InsertPosition, pivot string, element string) (int64, error) + LInsert(key string, insertPosition options.InsertPosition, pivot string, element string) (int64, error) BLPop(keys []string, timeoutSecs float64) ([]string, error) @@ -48,28 +52,33 @@ type ListCommands interface { LPushX(key string, elements []string) (int64, error) - LMPop(keys []string, listDirection ListDirection) (map[string][]string, error) + LMPop(keys []string, listDirection options.ListDirection) (map[string][]string, error) - LMPopCount(keys []string, listDirection ListDirection, count int64) (map[string][]string, error) + LMPopCount(keys []string, listDirection options.ListDirection, count int64) (map[string][]string, error) - BLMPop(keys []string, listDirection ListDirection, timeoutSecs float64) (map[string][]string, error) + BLMPop(keys []string, listDirection options.ListDirection, timeoutSecs float64) (map[string][]string, error) BLMPopCount( keys []string, - listDirection ListDirection, + listDirection options.ListDirection, count int64, timeoutSecs float64, ) (map[string][]string, error) LSet(key string, index int64, element string) (string, error) - LMove(source string, destination string, whereFrom ListDirection, whereTo ListDirection) (Result[string], error) + LMove( + source string, + destination string, + whereFrom options.ListDirection, + whereTo options.ListDirection, + ) (Result[string], error) BLMove( source string, destination string, - whereFrom ListDirection, - whereTo ListDirection, + whereFrom options.ListDirection, + whereTo options.ListDirection, timeoutSecs float64, ) (Result[string], error) } diff --git a/go/api/list_commands_test.go b/go/api/list_commands_test.go index 4411ed8eca..9db68fa0fb 100644 --- a/go/api/list_commands_test.go +++ b/go/api/list_commands_test.go @@ -4,6 +4,8 @@ package api import ( "fmt" + + "github.com/valkey-io/valkey-glide/go/api/options" ) func ExampleGlideClient_LPush() { @@ -74,7 +76,7 @@ func ExampleGlideClient_LPosWithOptions() { result1, err := client.LPosWithOptions( "my_list", "e", - NewLPosOptionsBuilder().SetRank(2), + options.NewLPosOptions().SetRank(2), ) // (Returns the second occurrence of the element "e") if err != nil { fmt.Println("Glide example failed with an error: ", err) @@ -105,9 +107,9 @@ func ExampleGlideClient_LPosCount() { func ExampleGlideClient_LPosCountWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.RPush("my_list", []string{"a", "b", "c", "d", "e", "e", "e"}) - result1, err := client.LPosCountWithOptions("my_list", "e", 1, NewLPosOptionsBuilder().SetRank(2)) + result1, err := client.LPosCountWithOptions("my_list", "e", 1, options.NewLPosOptions().SetRank(2)) result2, err := client.LPosCountWithOptions("my_list", "e", 3, - NewLPosOptionsBuilder().SetRank(2).SetMaxLen(1000)) + options.NewLPosOptions().SetRank(2).SetMaxLen(1000)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -251,7 +253,7 @@ func ExampleGlideClient_LInsert() { var client *GlideClient = getExampleGlideClient() // example helper function client.Del([]string{"my_list"}) result, err := client.RPush("my_list", []string{"hello", "world"}) - result1, err := client.LInsert("my_list", Before, "world", "there") + result1, err := client.LInsert("my_list", options.Before, "world", "there") if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -339,7 +341,7 @@ func ExampleGlideClient_LPushX() { func ExampleGlideClient_LMPop() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) - result1, err := client.LMPop([]string{"my_list"}, Left) + result1, err := client.LMPop([]string{"my_list"}, options.Left) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -354,7 +356,7 @@ func ExampleGlideClient_LMPop() { func ExampleGlideClient_LMPopCount() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) - result1, err := client.LMPopCount([]string{"my_list"}, Left, 2) + result1, err := client.LMPopCount([]string{"my_list"}, options.Left, 2) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -369,7 +371,7 @@ func ExampleGlideClient_LMPopCount() { func ExampleGlideClient_BLMPop() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) - result1, err := client.BLMPop([]string{"my_list"}, Left, 0.1) + result1, err := client.BLMPop([]string{"my_list"}, options.Left, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -384,7 +386,7 @@ func ExampleGlideClient_BLMPop() { func ExampleGlideClient_BLMPopCount() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list", []string{"one", "two", "three"}) - result1, err := client.BLMPopCount([]string{"my_list"}, Left, 2, 0.1) + result1, err := client.BLMPopCount([]string{"my_list"}, options.Left, 2, 0.1) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -419,7 +421,7 @@ func ExampleGlideClient_LMove() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list1", []string{"two", "one"}) result1, err := client.LPush("my_list2", []string{"four", "three"}) - result2, err := client.LMove("my_list1", "my_list2", Left, Left) + result2, err := client.LMove("my_list1", "my_list2", options.Left, options.Left) result3, err := client.LRange("my_list1", 0, -1) result4, err := client.LRange("my_list2", 0, -1) if err != nil { @@ -443,7 +445,7 @@ func ExampleGlideClient_BLMove() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.LPush("my_list1", []string{"two", "one"}) result1, err := client.LPush("my_list2", []string{"four", "three"}) - result2, err := client.BLMove("my_list1", "my_list2", Left, Left, 0.1) + result2, err := client.BLMove("my_list1", "my_list2", options.Left, options.Left, 0.1) result3, err := client.LRange("my_list1", 0, -1) result4, err := client.LRange("my_list2", 0, -1) if err != nil { diff --git a/go/api/options/base_scan_options.go b/go/api/options/base_scan_options.go index 77cf06da76..e9684048d8 100644 --- a/go/api/options/base_scan_options.go +++ b/go/api/options/base_scan_options.go @@ -13,7 +13,7 @@ type BaseScanOptions struct { count int64 } -func NewBaseScanOptionsBuilder() *BaseScanOptions { +func NewBaseScanOptions() *BaseScanOptions { return &BaseScanOptions{} } diff --git a/go/api/options/bitcount_options.go b/go/api/options/bitcount_options.go index acd6939db9..da688220db 100644 --- a/go/api/options/bitcount_options.go +++ b/go/api/options/bitcount_options.go @@ -20,7 +20,7 @@ type BitCountOptions struct { bitMapIndexType BitmapIndexType } -func NewBitCountOptionsBuilder() *BitCountOptions { +func NewBitCountOptions() *BitCountOptions { return &BitCountOptions{} } diff --git a/go/api/command_options.go b/go/api/options/command_options.go similarity index 57% rename from go/api/command_options.go rename to go/api/options/command_options.go index 809121692d..b639e7bead 100644 --- a/go/api/command_options.go +++ b/go/api/options/command_options.go @@ -1,11 +1,10 @@ // Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 -package api +package options import ( "strconv" - "github.com/valkey-io/valkey-glide/go/api/config" "github.com/valkey-io/valkey-glide/go/api/errors" "github.com/valkey-io/valkey-glide/go/utils" ) @@ -28,7 +27,7 @@ type SetOptions struct { Expiry *Expiry } -func NewSetOptionsBuilder() *SetOptions { +func NewSetOptions() *SetOptions { return &SetOptions{} } @@ -47,7 +46,7 @@ func (setOptions *SetOptions) SetExpiry(expiry *Expiry) *SetOptions { return setOptions } -func (opts *SetOptions) toArgs() ([]string, error) { +func (opts *SetOptions) ToArgs() ([]string, error) { args := []string{} var err error if opts.ConditionalSet != "" { @@ -83,7 +82,7 @@ type GetExOptions struct { Expiry *Expiry } -func NewGetExOptionsBuilder() *GetExOptions { +func NewGetExOptions() *GetExOptions { return &GetExOptions{} } @@ -92,7 +91,7 @@ func (getExOptions *GetExOptions) SetExpiry(expiry *Expiry) *GetExOptions { return getExOptions } -func (opts *GetExOptions) toArgs() ([]string, error) { +func (opts *GetExOptions) ToArgs() ([]string, error) { args := []string{} var err error @@ -110,32 +109,7 @@ func (opts *GetExOptions) toArgs() ([]string, error) { return args, err } -const returnOldValue = "GET" - -// A ConditionalSet defines whether a new value should be set or not. -type ConditionalSet string - -const ( - // OnlyIfExists only sets the key if it already exists. Equivalent to "XX" in the valkey API. - OnlyIfExists ConditionalSet = "XX" - // OnlyIfDoesNotExist only sets the key if it does not already exist. Equivalent to "NX" in the valkey API. - OnlyIfDoesNotExist ConditionalSet = "NX" -) - -type ExpireCondition string - -const ( - // HasExistingExpiry only sets the key if it already exists. Equivalent to "XX" in the valkey API. - HasExistingExpiry ExpireCondition = "XX" - // HasNoExpiry only sets the key if it does not already exist. Equivalent to "NX" in the valkey API. - HasNoExpiry ExpireCondition = "NX" - // NewExpiryGreaterThanCurrent only sets the key if its greater than current. Equivalent to "GT" in the valkey API. - NewExpiryGreaterThanCurrent ExpireCondition = "GT" - // NewExpiryLessThanCurrent only sets the key if its lesser than current. Equivalent to "LT" in the valkey API. - NewExpiryLessThanCurrent ExpireCondition = "LT" -) - -func (expireCondition ExpireCondition) toString() (string, error) { +func (expireCondition ExpireCondition) ToString() (string, error) { switch expireCondition { case HasExistingExpiry: return string(HasExistingExpiry), nil @@ -156,7 +130,7 @@ type Expiry struct { Count uint64 } -func NewExpiryBuilder() *Expiry { +func NewExpiry() *Expiry { return &Expiry{} } @@ -170,18 +144,6 @@ func (ex *Expiry) SetCount(count uint64) *Expiry { return ex } -// An ExpiryType is used to configure the type of expiration for a value. -type ExpiryType string - -const ( - KeepExisting ExpiryType = "KEEPTTL" // keep the existing expiration of the value - Seconds ExpiryType = "EX" // expire the value after [api.Expiry.Count] seconds - Milliseconds ExpiryType = "PX" // expire the value after [api.Expiry.Count] milliseconds - UnixSeconds ExpiryType = "EXAT" // expire the value after the Unix time specified by [api.Expiry.Count], in seconds - UnixMilliseconds ExpiryType = "PXAT" // expire the value after the Unix time specified by [api.Expiry.Count], in milliseconds - Persist ExpiryType = "PERSIST" // Remove the expiry associated with the key -) - // LPosOptions represents optional arguments for the [api.ListCommands.LPosWithOptions] and // [api.ListCommands.LPosCountWithOptions] commands. // @@ -199,7 +161,7 @@ type LPosOptions struct { MaxLen int64 } -func NewLPosOptionsBuilder() *LPosOptions { +func NewLPosOptions() *LPosOptions { return &LPosOptions{} } @@ -215,7 +177,7 @@ func (lposOptions *LPosOptions) SetMaxLen(maxLen int64) *LPosOptions { return lposOptions } -func (opts *LPosOptions) toArgs() []string { +func (opts *LPosOptions) ToArgs() ([]string, error) { args := []string{} if opts.IsRankSet { args = append(args, RankKeyword, utils.IntToString(opts.Rank)) @@ -225,31 +187,10 @@ func (opts *LPosOptions) toArgs() []string { args = append(args, MaxLenKeyword, utils.IntToString(opts.MaxLen)) } - return args + return args, nil } -const ( - CountKeyword string = "COUNT" // Valkey API keyword used to extract specific number of matching indices from a list. - RankKeyword string = "RANK" // Valkey API keyword use to determine the rank of the match to return. - MaxLenKeyword string = "MAXLEN" // Valkey API keyword used to determine the maximum number of list items to compare. - MatchKeyword string = "MATCH" // Valkey API keyword used to indicate the match filter. -) - -// A InsertPosition defines where to insert new elements into a list. -// -// See [valkey.io] -// -// [valkey.io]: https://valkey.io/commands/linsert/ -type InsertPosition string - -const ( - // Insert new element before the pivot. - Before InsertPosition = "BEFORE" - // Insert new element after the pivot. - After InsertPosition = "AFTER" -) - -func (insertPosition InsertPosition) toString() (string, error) { +func (insertPosition InsertPosition) ToString() (string, error) { switch insertPosition { case Before: return string(Before), nil @@ -260,17 +201,7 @@ func (insertPosition InsertPosition) toString() (string, error) { } } -// Enumeration representing element popping or adding direction for the [api.ListCommands]. -type ListDirection string - -const ( - // Represents the option that elements should be popped from or added to the left side of a list. - Left ListDirection = "LEFT" - // Represents the option that elements should be popped from or added to the right side of a list. - Right ListDirection = "RIGHT" -) - -func (listDirection ListDirection) toString() (string, error) { +func (listDirection ListDirection) ToString() (string, error) { switch listDirection { case Left: return string(Left), nil @@ -281,18 +212,7 @@ func (listDirection ListDirection) toString() (string, error) { } } -// Mandatory option for [ZMPop] and for [BZMPop]. -// Defines which elements to pop from the sorted set. -type ScoreFilter string - -const ( - // Pop elements with the highest scores. - MAX ScoreFilter = "MAX" - // Pop elements with the lowest scores. - MIN ScoreFilter = "MIN" -) - -func (scoreFilter ScoreFilter) toString() (string, error) { +func (scoreFilter ScoreFilter) ToString() (string, error) { switch scoreFilter { case MAX: return string(MAX), nil @@ -317,27 +237,19 @@ type RestoreOptions struct { eviction Eviction } -func NewRestoreOptionsBuilder() *RestoreOptions { +func NewRestoreOptions() *RestoreOptions { return &RestoreOptions{} } -const ( - // Subcommand string to replace existing key. - Replace_keyword = "REPLACE" - - // Subcommand string to represent absolute timestamp (in milliseconds) for TTL. - ABSTTL_keyword string = "ABSTTL" -) - // Custom setter methods to replace existing key. func (restoreOption *RestoreOptions) SetReplace() *RestoreOptions { - restoreOption.replace = Replace_keyword + restoreOption.replace = ReplaceKeyword return restoreOption } // Custom setter methods to represent absolute timestamp (in milliseconds) for TTL. func (restoreOption *RestoreOptions) SetABSTTL() *RestoreOptions { - restoreOption.absTTL = ABSTTL_keyword + restoreOption.absTTL = ABSTTLKeyword return restoreOption } @@ -349,15 +261,6 @@ type Eviction struct { Count int64 } -type EvictionType string - -const ( - // It represents the idletime of object - IDLETIME EvictionType = "IDLETIME" - // It represents the frequency of object - FREQ EvictionType = "FREQ" -) - // Custom setter methods set the idletime/frequency of object. func (restoreOption *RestoreOptions) SetEviction(evictionType EvictionType, count int64) *RestoreOptions { restoreOption.eviction.Type = evictionType @@ -365,7 +268,7 @@ func (restoreOption *RestoreOptions) SetEviction(evictionType EvictionType, coun return restoreOption } -func (opts *RestoreOptions) toArgs() ([]string, error) { +func (opts *RestoreOptions) ToArgs() ([]string, error) { args := []string{} var err error if opts.replace != "" { @@ -380,45 +283,6 @@ func (opts *RestoreOptions) toArgs() ([]string, error) { return args, err } -type Section string - -const ( - // SERVER: General information about the server - Server Section = "server" - // CLIENTS: Client connections section - Clients Section = "clients" - // MEMORY: Memory consumption related information - Memory Section = "memory" - // PERSISTENCE: RDB and AOF related information - Persistence Section = "persistence" - // STATS: General statistics - Stats Section = "stats" - // REPLICATION: Master/replica replication information - Replication Section = "replication" - // CPU: CPU consumption statistics - Cpu Section = "cpu" - // COMMANDSTATS: Valkey command statistics - Commandstats Section = "commandstats" - // LATENCYSTATS: Valkey command latency percentile distribution statistics - Latencystats Section = "latencystats" - // SENTINEL: Valkey Sentinel section (only applicable to Sentinel instances) - Sentinel Section = "sentinel" - // CLUSTER: Valkey Cluster section - Cluster Section = "cluster" - // MODULES: Modules section - Modules Section = "modules" - // KEYSPACE: Database related statistics - Keyspace Section = "keyspace" - // ERRORSTATS: Valkey error statistics - Errorstats Section = "errorstats" - // ALL: Return all sections (excluding module generated ones) - All Section = "all" - // DEFAULT: Return only the default set of sections - Default Section = "default" - // EVERYTHING: Includes all and modules - Everything Section = "everything" -) - // Optional arguments for `Info` for standalone client type InfoOptions struct { // A list of [Section] values specifying which sections of information to retrieve. @@ -430,21 +294,18 @@ type InfoOptions struct { // Optional arguments for `Info` for cluster client type ClusterInfoOptions struct { *InfoOptions - // Specifies the routing configuration for the command. - // The client will route the command to the nodes defined by `Route`. - // The command will be routed to all primary nodes, unless `Route` is provided. - Route *config.Route + *RouteOption } -func (opts *InfoOptions) toArgs() []string { +func (opts *InfoOptions) ToArgs() ([]string, error) { if opts == nil { - return []string{} + return []string{}, nil } args := make([]string, 0, len(opts.Sections)) for _, section := range opts.Sections { args = append(args, string(section)) } - return args + return args, nil } // Optional arguments to Copy(source string, destination string, option *CopyOptions) @@ -457,7 +318,7 @@ type CopyOptions struct { dbDestination int64 } -func NewCopyOptionsBuilder() *CopyOptions { +func NewCopyOptions() *CopyOptions { return &CopyOptions{replace: false} } @@ -473,11 +334,11 @@ func (copyOption *CopyOptions) SetDBDestination(destinationDB int64) *CopyOption return copyOption } -func (opts *CopyOptions) toArgs() ([]string, error) { +func (opts *CopyOptions) ToArgs() ([]string, error) { args := []string{} var err error if opts.replace { - args = append(args, string("REPLACE")) + args = append(args, string(ReplaceKeyword)) } if opts.dbDestination >= 0 { args = append(args, "DB", utils.IntToString(opts.dbDestination)) diff --git a/go/api/options/constants.go b/go/api/options/constants.go index d140410cd3..e0e1abed0c 100644 --- a/go/api/options/constants.go +++ b/go/api/options/constants.go @@ -3,15 +3,36 @@ package options const ( - CountKeyword string = "COUNT" // Valkey API keyword used to extract specific number of matching indices from a list. - MatchKeyword string = "MATCH" // Valkey API keyword used to indicate the match filter. - NoValue string = "NOVALUE" // Valkey API keyword for the no value option for hcsan command. - WithScore string = "WITHSCORE" // Valkey API keyword for the with score option for zrank and zrevrank commands. - WithScores string = "WITHSCORES" // Valkey API keyword for ZRandMember and ZDiff command to return scores along with members. - NoScores string = "NOSCORES" // Valkey API keyword for the no scores option for zscan command. - WithValues string = "WITHVALUES" // Valkey API keyword to query hash values along their names in `HRANDFIELD`. - AggregateKeyWord string = "AGGREGATE" // Valkey API keyword for the aggregate option for multiple commands. - WeightsKeyword string = "WEIGHTS" // Valkey API keyword for the weights option for multiple commands. + CountKeyword string = "COUNT" // Valkey API keyword used to extract specific number of matching indices from a list. + MatchKeyword string = "MATCH" // Valkey API keyword used to indicate the match filter. + NoValueKeyword string = "NOVALUE" // Valkey API keyword for the no value option for hcsan command. + WithScoreKeyword string = "WITHSCORE" // Valkey API keyword for the with score option for zrank and zrevrank commands. + WithScoresKeyword string = "WITHSCORES" // Valkey API keyword for ZRandMember and ZDiff command to return scores along with members. + NoScoresKeyword string = "NOSCORES" // Valkey API keyword for the no scores option for zscan command. + WithValuesKeyword string = "WITHVALUES" // Valkey API keyword to query hash values along their names in `HRANDFIELD`. + AggregateKeyWord string = "AGGREGATE" // Valkey API keyword for the aggregate option for multiple commands. + WeightsKeyword string = "WEIGHTS" // Valkey API keyword for the weights option for multiple commands. + RankKeyword string = "RANK" // Valkey API keyword use to determine the rank of the match to return. + MaxLenKeyword string = "MAXLEN" // Valkey API keyword used to determine the maximum number of list items to compare. + ReplaceKeyword string = "REPLACE" // Subcommand string to replace existing key. + ABSTTLKeyword string = "ABSTTL" // Subcommand string to represent absolute timestamp (in milliseconds) for TTL. + StoreKeyword string = "STORE" + DbKeyword string = "DB" + /// Valkey API keywords for stream commands + IdleKeyword string = "IDLE" // ValKey API string to designate IDLE time in milliseconds + TimeKeyword string = "TIME" // ValKey API string to designate TIME time in unix-milliseconds + RetryCountKeyword string = "RETRYCOUNT" // ValKey API string to designate RETRYCOUNT + ForceKeyword string = "FORCE" // ValKey API string to designate FORCE + JustIdKeyword string = "JUSTID" // ValKey API string to designate JUSTID + EntriesReadKeyword string = "ENTRIESREAD" + MakeStreamKeyword string = "MKSTREAM" + NoMakeStreamKeyword string = "NOMKSTREAM" + BlockKeyword string = "BLOCK" + NoAckKeyword string = "NOACK" + LimitKeyword string = "LIMIT" + MinIdKeyword string = "MINID" + GroupKeyword string = "GROUP" + StreamsKeyword string = "STREAMS" ) type InfBoundary string @@ -22,3 +43,130 @@ const ( // The lowest bound in the sorted set NegativeInfinity InfBoundary = "-" ) + +const returnOldValue = "GET" + +// A ConditionalSet defines whether a new value should be set or not. +type ConditionalSet string + +const ( + // OnlyIfExists only sets the key if it already exists. Equivalent to "XX" in the valkey API. + OnlyIfExists ConditionalSet = "XX" + // OnlyIfDoesNotExist only sets the key if it does not already exist. Equivalent to "NX" in the valkey API. + OnlyIfDoesNotExist ConditionalSet = "NX" +) + +type ExpireCondition string + +const ( + // HasExistingExpiry only sets the key if it already exists. Equivalent to "XX" in the valkey API. + HasExistingExpiry ExpireCondition = "XX" + // HasNoExpiry only sets the key if it does not already exist. Equivalent to "NX" in the valkey API. + HasNoExpiry ExpireCondition = "NX" + // NewExpiryGreaterThanCurrent only sets the key if its greater than current. Equivalent to "GT" in the valkey API. + NewExpiryGreaterThanCurrent ExpireCondition = "GT" + // NewExpiryLessThanCurrent only sets the key if its lesser than current. Equivalent to "LT" in the valkey API. + NewExpiryLessThanCurrent ExpireCondition = "LT" +) + +// An ExpiryType is used to configure the type of expiration for a value. +type ExpiryType string + +const ( + // Keep the existing expiration of the value. + KeepExisting ExpiryType = "KEEPTTL" + // Expire the value after [options.Expiry.Count] seconds + Seconds ExpiryType = "EX" + // Expire the value after [options.Expiry.Count] milliseconds. + Milliseconds ExpiryType = "PX" + // Expire the value after the Unix time specified by [options.Expiry.Count], in seconds. + UnixSeconds ExpiryType = "EXAT" + // Expire the value after the Unix time specified by [options.Expiry.Count], in milliseconds. + UnixMilliseconds ExpiryType = "PXAT" + // Remove the expiry associated with the key. + Persist ExpiryType = "PERSIST" +) + +// A InsertPosition defines where to insert new elements into a list. +// +// See [valkey.io] +// +// [valkey.io]: https://valkey.io/commands/linsert/ +type InsertPosition string + +const ( + // Insert new element before the pivot. + Before InsertPosition = "BEFORE" + // Insert new element after the pivot. + After InsertPosition = "AFTER" +) + +// Enumeration representing element popping or adding direction for the [api.ListCommands]. +type ListDirection string + +const ( + // Represents the option that elements should be popped from or added to the left side of a list. + Left ListDirection = "LEFT" + // Represents the option that elements should be popped from or added to the right side of a list. + Right ListDirection = "RIGHT" +) + +// Mandatory parameter for [ZMPop] and for [BZMPop]. +// Defines which elements to pop from the sorted set. +type ScoreFilter string + +const ( + // Pop elements with the highest scores. + MAX ScoreFilter = "MAX" + // Pop elements with the lowest scores. + MIN ScoreFilter = "MIN" +) + +type EvictionType string + +const ( + // It represents the idletime of object. + IDLETIME EvictionType = "IDLETIME" + // It represents the frequency of object. + FREQ EvictionType = "FREQ" +) + +// Enumeration representing information section which could be queried by `INFO` command. +type Section string + +const ( + // SERVER: General information about the server + Server Section = "server" + // CLIENTS: Client connections section + Clients Section = "clients" + // MEMORY: Memory consumption related information + Memory Section = "memory" + // PERSISTENCE: RDB and AOF related information + Persistence Section = "persistence" + // STATS: General statistics + Stats Section = "stats" + // REPLICATION: Master/replica replication information + Replication Section = "replication" + // CPU: CPU consumption statistics + Cpu Section = "cpu" + // COMMANDSTATS: Valkey command statistics + Commandstats Section = "commandstats" + // LATENCYSTATS: Valkey command latency percentile distribution statistics + Latencystats Section = "latencystats" + // SENTINEL: Valkey Sentinel section (only applicable to Sentinel instances) + Sentinel Section = "sentinel" + // CLUSTER: Valkey Cluster section + Cluster Section = "cluster" + // MODULES: Modules section + Modules Section = "modules" + // KEYSPACE: Database related statistics + Keyspace Section = "keyspace" + // ERRORSTATS: Valkey error statistics + Errorstats Section = "errorstats" + // ALL: Return all sections (excluding module generated ones) + All Section = "all" + // DEFAULT: Return only the default set of sections + Default Section = "default" + // EVERYTHING: Includes all and modules + Everything Section = "everything" +) diff --git a/go/api/options/db_size_options.go b/go/api/options/db_size_options.go index 0257391422..2a5cb08fd5 100644 --- a/go/api/options/db_size_options.go +++ b/go/api/options/db_size_options.go @@ -8,7 +8,7 @@ type DBSizeOptions struct { Route config.Route } -func NewTimeOptionsBuilder() *DBSizeOptions { +func NewTimeOptions() *DBSizeOptions { return &DBSizeOptions{} } diff --git a/go/api/options/echo_options.go b/go/api/options/echo_options.go index 383f46a6ce..2b56f6ec5e 100644 --- a/go/api/options/echo_options.go +++ b/go/api/options/echo_options.go @@ -10,18 +10,16 @@ type EchoOptions struct { // Optional arguments for `Echo` for cluster client type ClusterEchoOptions struct { *EchoOptions - // Specifies the routing configuration for the command. - // The client will route the command to the nodes defined by *Route*. *RouteOption } -func (opts *EchoOptions) ToArgs() []string { +func (opts *EchoOptions) ToArgs() ([]string, error) { if opts == nil { - return []string{} + return []string{}, nil } args := []string{} if opts.Message != "" { args = append(args, opts.Message) } - return args + return args, nil } diff --git a/go/api/options/hscan_options.go b/go/api/options/hscan_options.go index a90b2d369a..c3f12b864d 100644 --- a/go/api/options/hscan_options.go +++ b/go/api/options/hscan_options.go @@ -8,7 +8,7 @@ type HashScanOptions struct { noValue bool } -func NewHashScanOptionsBuilder() *HashScanOptions { +func NewHashScanOptions() *HashScanOptions { return &HashScanOptions{} } @@ -37,7 +37,7 @@ func (options *HashScanOptions) ToArgs() ([]string, error) { args = append(args, baseArgs...) if options.noValue { - args = append(args, NoValue) + args = append(args, NoValueKeyword) } return args, err } diff --git a/go/api/options/ping_options.go b/go/api/options/ping_options.go index 984de736d5..c9d02babe6 100644 --- a/go/api/options/ping_options.go +++ b/go/api/options/ping_options.go @@ -2,10 +2,6 @@ package options -import ( - "github.com/valkey-io/valkey-glide/go/api/config" -) - // Optional arguments for `Ping` for standalone client type PingOptions struct { Message string @@ -14,18 +10,16 @@ type PingOptions struct { // Optional arguments for `Ping` for cluster client type ClusterPingOptions struct { *PingOptions - // Specifies the routing configuration for the command. - // The client will route the command to the nodes defined by *Route*. - Route *config.Route + *RouteOption } -func (opts *PingOptions) ToArgs() []string { +func (opts *PingOptions) ToArgs() ([]string, error) { if opts == nil { - return []string{} + return []string{}, nil } args := []string{} if opts.Message != "" { args = append(args, opts.Message) } - return args + return args, nil } diff --git a/go/api/options/sort_options.go b/go/api/options/sort_options.go index 935c82956a..e0ea2f3dfa 100644 --- a/go/api/options/sort_options.go +++ b/go/api/options/sort_options.go @@ -100,7 +100,7 @@ func (opts *SortOptions) AddGetPattern(getPattern string) *SortOptions { } // ToArgs creates the arguments to be used in SORT and SORT_RO commands. -func (opts *SortOptions) ToArgs() []string { +func (opts *SortOptions) ToArgs() ([]string, error) { var args []string if opts.SortLimit != nil { @@ -127,5 +127,5 @@ func (opts *SortOptions) ToArgs() []string { for _, getPattern := range opts.GetPatterns { args = append(args, GET_COMMAND_STRING, getPattern) } - return args + return args, nil } diff --git a/go/api/options/stream_options.go b/go/api/options/stream_options.go index 32aa02944c..c4c8b09219 100644 --- a/go/api/options/stream_options.go +++ b/go/api/options/stream_options.go @@ -48,7 +48,7 @@ func (xao *XAddOptions) SetTrimOptions(options *XTrimOptions) *XAddOptions { func (xao *XAddOptions) ToArgs() ([]string, error) { args := []string{} if xao.makeStream == triStateBoolFalse { - args = append(args, "NOMKSTREAM") + args = append(args, NoMakeStreamKeyword) } if xao.trimOptions != nil { moreArgs, err := xao.trimOptions.ToArgs() @@ -75,12 +75,12 @@ type XTrimOptions struct { // Option to trim the stream according to minimum ID. func NewXTrimOptionsWithMinId(threshold string) *XTrimOptions { - return &XTrimOptions{threshold: threshold, method: "MINID"} + return &XTrimOptions{threshold: threshold, method: MinIdKeyword} } // Option to trim the stream according to maximum stream length. func NewXTrimOptionsWithMaxLen(threshold int64) *XTrimOptions { - return &XTrimOptions{threshold: utils.IntToString(threshold), method: "MAXLEN"} + return &XTrimOptions{threshold: utils.IntToString(threshold), method: MaxLenKeyword} } // Match exactly on the threshold. @@ -111,7 +111,7 @@ func (xTrimOptions *XTrimOptions) ToArgs() ([]string, error) { } args = append(args, xTrimOptions.threshold) if xTrimOptions.limit > 0 { - args = append(args, "LIMIT", utils.IntToString(xTrimOptions.limit)) + args = append(args, LimitKeyword, utils.IntToString(xTrimOptions.limit)) } return args, nil } @@ -127,7 +127,7 @@ func NewXAutoClaimOptionsWithCount(count int64) *XAutoClaimOptions { } func (xacp *XAutoClaimOptions) ToArgs() ([]string, error) { - return []string{"COUNT", utils.IntToString(xacp.count)}, nil + return []string{CountKeyword, utils.IntToString(xacp.count)}, nil } // Optional arguments for `XRead` in [StreamCommands] @@ -156,10 +156,10 @@ func (xro *XReadOptions) SetBlock(block int64) *XReadOptions { func (xro *XReadOptions) ToArgs() ([]string, error) { args := []string{} if xro.count >= 0 { - args = append(args, "COUNT", utils.IntToString(xro.count)) + args = append(args, CountKeyword, utils.IntToString(xro.count)) } if xro.block >= 0 { - args = append(args, "BLOCK", utils.IntToString(xro.block)) + args = append(args, BlockKeyword, utils.IntToString(xro.block)) } return args, nil } @@ -198,13 +198,13 @@ func (xrgo *XReadGroupOptions) SetNoAck() *XReadGroupOptions { func (xrgo *XReadGroupOptions) ToArgs() ([]string, error) { args := []string{} if xrgo.count >= 0 { - args = append(args, "COUNT", utils.IntToString(xrgo.count)) + args = append(args, CountKeyword, utils.IntToString(xrgo.count)) } if xrgo.block >= 0 { - args = append(args, "BLOCK", utils.IntToString(xrgo.block)) + args = append(args, BlockKeyword, utils.IntToString(xrgo.block)) } if xrgo.noAck { - args = append(args, "NOACK") + args = append(args, NoAckKeyword) } return args, nil } @@ -247,7 +247,7 @@ func (xpo *XPendingOptions) ToArgs() ([]string, error) { args := []string{} if xpo.minIdleTime > 0 { - args = append(args, "IDLE") + args = append(args, IdleKeyword) args = append(args, utils.IntToString(xpo.minIdleTime)) } @@ -289,11 +289,11 @@ func (xgco *XGroupCreateOptions) ToArgs() ([]string, error) { // if minIdleTime is set, we need to add an `IDLE` argument along with the minIdleTime if xgco.mkStream { - args = append(args, "MKSTREAM") + args = append(args, MakeStreamKeyword) } if xgco.entriesRead > -1 { - args = append(args, "ENTRIESREAD", utils.IntToString(xgco.entriesRead)) + args = append(args, EntriesReadKeyword, utils.IntToString(xgco.entriesRead)) } return args, nil @@ -321,7 +321,7 @@ func (xgsio *XGroupSetIdOptions) ToArgs() ([]string, error) { var args []string if xgsio.entriesRead > -1 { - args = append(args, "ENTRIESREAD", utils.IntToString(xgsio.entriesRead)) + args = append(args, EntriesReadKeyword, utils.IntToString(xgsio.entriesRead)) } return args, nil @@ -363,37 +363,23 @@ func (sco *StreamClaimOptions) SetForce() *StreamClaimOptions { return sco } -// Valkey API keywords for stream claim options -const ( - // ValKey API string to designate IDLE time in milliseconds - IDLE_VALKEY_API string = "IDLE" - // ValKey API string to designate TIME time in unix-milliseconds - TIME_VALKEY_API string = "TIME" - // ValKey API string to designate RETRYCOUNT - RETRY_COUNT_VALKEY_API string = "RETRYCOUNT" - // ValKey API string to designate FORCE - FORCE_VALKEY_API string = "FORCE" - // ValKey API string to designate JUSTID - JUST_ID_VALKEY_API string = "JUSTID" -) - func (sco *StreamClaimOptions) ToArgs() ([]string, error) { optionArgs := []string{} if sco.idleTime > 0 { - optionArgs = append(optionArgs, IDLE_VALKEY_API, utils.IntToString(sco.idleTime)) + optionArgs = append(optionArgs, IdleKeyword, utils.IntToString(sco.idleTime)) } if sco.idleUnixTime > 0 { - optionArgs = append(optionArgs, TIME_VALKEY_API, utils.IntToString(sco.idleUnixTime)) + optionArgs = append(optionArgs, TimeKeyword, utils.IntToString(sco.idleUnixTime)) } if sco.retryCount > 0 { - optionArgs = append(optionArgs, RETRY_COUNT_VALKEY_API, utils.IntToString(sco.retryCount)) + optionArgs = append(optionArgs, RetryCountKeyword, utils.IntToString(sco.retryCount)) } if sco.isForce { - optionArgs = append(optionArgs, FORCE_VALKEY_API) + optionArgs = append(optionArgs, ForceKeyword) } return optionArgs, nil @@ -435,7 +421,7 @@ func (sro *StreamRangeOptions) ToArgs() ([]string, error) { var args []string if sro.countIsSet { - args = append(args, "COUNT", utils.IntToString(sro.count)) + args = append(args, CountKeyword, utils.IntToString(sro.count)) } return args, nil diff --git a/go/api/options/weight_aggregate_options.go b/go/api/options/weight_aggregate_options.go index 6c26556d18..c18c082f30 100644 --- a/go/api/options/weight_aggregate_options.go +++ b/go/api/options/weight_aggregate_options.go @@ -14,15 +14,15 @@ const ( ) // converts the Aggregate to its Valkey API representation -func (a Aggregate) ToArgs() []string { - return []string{AggregateKeyWord, string(a)} +func (a Aggregate) ToArgs() ([]string, error) { + return []string{AggregateKeyWord, string(a)}, nil } // This is a basic interface. Please use one of the following implementations: // - KeyArray // - WeightedKeys type KeysOrWeightedKeys interface { - ToArgs() []string + ToArgs() ([]string, error) } // represents a list of keys of the sorted sets involved in the aggregation operation @@ -31,10 +31,10 @@ type KeyArray struct { } // converts the KeyArray to its Valkey API representation -func (k KeyArray) ToArgs() []string { +func (k KeyArray) ToArgs() ([]string, error) { args := []string{utils.IntToString(int64(len(k.Keys)))} args = append(args, k.Keys...) - return args + return args, nil } type KeyWeightPair struct { @@ -48,7 +48,7 @@ type WeightedKeys struct { } // converts the WeightedKeys to its Valkey API representation -func (w WeightedKeys) ToArgs() []string { +func (w WeightedKeys) ToArgs() ([]string, error) { keys := make([]string, 0, len(w.KeyWeightPairs)) weights := make([]string, 0, len(w.KeyWeightPairs)) args := make([]string, 0) @@ -60,5 +60,5 @@ func (w WeightedKeys) ToArgs() []string { args = append(args, keys...) args = append(args, WeightsKeyword) args = append(args, weights...) - return args + return args, nil } diff --git a/go/api/options/zadd_options.go b/go/api/options/zadd_options.go index 491addb3e2..ce2d75a417 100644 --- a/go/api/options/zadd_options.go +++ b/go/api/options/zadd_options.go @@ -10,7 +10,7 @@ import ( // Optional arguments to `ZAdd` in [SortedSetCommands] type ZAddOptions struct { - conditionalChange ConditionalChange + conditionalChange ConditionalSet updateOptions UpdateOptions changed bool incr bool @@ -18,12 +18,12 @@ type ZAddOptions struct { member string } -func NewZAddOptionsBuilder() *ZAddOptions { +func NewZAddOptions() *ZAddOptions { return &ZAddOptions{} } // `conditionalChange` defines conditions for updating or adding elements with `ZADD` command. -func (options *ZAddOptions) SetConditionalChange(c ConditionalChange) *ZAddOptions { +func (options *ZAddOptions) SetConditionalChange(c ConditionalSet) *ZAddOptions { options.conditionalChange = c return options } @@ -78,16 +78,6 @@ func (opts *ZAddOptions) ToArgs() ([]string, error) { return args, err } -// A ConditionalSet defines whether a new value should be set or not. -type ConditionalChange string - -const ( - // Only update elements that already exist. Don't add new elements. Equivalent to "XX" in the Valkey API. - OnlyIfExists ConditionalChange = "XX" - // Only add new elements. Don't update already existing elements. Equivalent to "NX" in the Valkey API. - OnlyIfDoesNotExist ConditionalChange = "NX" -) - type UpdateOptions string const ( diff --git a/go/api/options/zcount_options.go b/go/api/options/zcount_options.go index d28cd49c33..817624ba2a 100644 --- a/go/api/options/zcount_options.go +++ b/go/api/options/zcount_options.go @@ -14,7 +14,7 @@ type ZCountRange struct { } // Create a new Zcount range. -func NewZCountRangeBuilder(min scoreBoundary, max scoreBoundary) *ZCountRange { +func NewZCountRange(min scoreBoundary, max scoreBoundary) *ZCountRange { return &ZCountRange{min, max} } diff --git a/go/api/options/zinter_options.go b/go/api/options/zinter_options.go index 0b0728886d..929ccd91b0 100644 --- a/go/api/options/zinter_options.go +++ b/go/api/options/zinter_options.go @@ -7,7 +7,7 @@ type ZInterOptions struct { aggregate Aggregate } -func NewZInterOptionsBuilder() *ZInterOptions { +func NewZInterOptions() *ZInterOptions { return &ZInterOptions{} } @@ -21,7 +21,11 @@ func (options *ZInterOptions) ToArgs() ([]string, error) { args := []string{} if options.aggregate != "" { - args = append(args, options.aggregate.ToArgs()...) + aggArgs, err := options.aggregate.ToArgs() + if err != nil { + return nil, err + } + args = append(args, aggArgs...) } return args, nil diff --git a/go/api/options/zrange_options.go b/go/api/options/zrange_options.go index 068dc61652..5645c4e3ff 100644 --- a/go/api/options/zrange_options.go +++ b/go/api/options/zrange_options.go @@ -11,7 +11,7 @@ import ( // - For range queries by lexicographical order, use `RangeByLex`. // - For range queries by score, use `RangeByScore`. type ZRangeQuery interface { - ToArgs() []string + ToArgs() ([]string, error) } type ZRemRangeQuery interface { @@ -85,8 +85,8 @@ type Limit struct { count int64 } -func (limit *Limit) toArgs() []string { - return []string{"LIMIT", utils.IntToString(limit.offset), utils.IntToString(limit.count)} +func (limit *Limit) toArgs() ([]string, error) { + return []string{"LIMIT", utils.IntToString(limit.offset), utils.IntToString(limit.count)}, nil } // Queries a range of elements from a sorted set by theirs index. @@ -105,13 +105,13 @@ func (rbi *RangeByIndex) SetReverse() *RangeByIndex { return rbi } -func (rbi *RangeByIndex) ToArgs() []string { +func (rbi *RangeByIndex) ToArgs() ([]string, error) { args := make([]string, 0, 3) args = append(args, utils.IntToString(rbi.start), utils.IntToString(rbi.end)) if rbi.reverse { args = append(args, "REV") } - return args + return args, nil } // Queries a range of elements from a sorted set by theirs score. @@ -136,20 +136,24 @@ func (rbs *RangeByScore) SetLimit(offset, count int64) *RangeByScore { return rbs } -func (rbs *RangeByScore) ToArgs() []string { +func (rbs *RangeByScore) ToArgs() ([]string, error) { args := make([]string, 0, 7) args = append(args, string(rbs.start), string(rbs.end), "BYSCORE") if rbs.reverse { args = append(args, "REV") } if rbs.Limit != nil { - args = append(args, rbs.Limit.toArgs()...) + limitArgs, err := rbs.Limit.toArgs() + if err != nil { + return nil, err + } + args = append(args, limitArgs...) } - return args + return args, nil } -func (rbs *RangeByScore) ToArgsRemRange() []string { - return []string{string(rbs.start), string(rbs.end)} +func (rbs *RangeByScore) ToArgsRemRange() ([]string, error) { + return []string{string(rbs.start), string(rbs.end)}, nil } // Queries a range of elements from a sorted set by theirs lexicographical order. @@ -174,20 +178,24 @@ func (rbl *RangeByLex) SetLimit(offset, count int64) *RangeByLex { return rbl } -func (rbl *RangeByLex) ToArgs() []string { +func (rbl *RangeByLex) ToArgs() ([]string, error) { args := make([]string, 0, 7) args = append(args, string(rbl.start), string(rbl.end), "BYLEX") if rbl.reverse { args = append(args, "REV") } if rbl.Limit != nil { - args = append(args, rbl.Limit.toArgs()...) + limitArgs, err := rbl.Limit.toArgs() + if err != nil { + return nil, err + } + args = append(args, limitArgs...) } - return args + return args, nil } -func (rbl *RangeByLex) ToArgsRemRange() []string { - return []string{string(rbl.start), string(rbl.end)} +func (rbl *RangeByLex) ToArgsRemRange() ([]string, error) { + return []string{string(rbl.start), string(rbl.end)}, nil } // Query for `ZRangeWithScores` in [SortedSetCommands] @@ -197,7 +205,7 @@ type ZRangeQueryWithScores interface { // A dummy interface to distinguish queries for `ZRange` and `ZRangeWithScores` // `ZRangeWithScores` does not support BYLEX dummy() - ToArgs() []string + ToArgs() ([]string, error) } func (q *RangeByIndex) dummy() {} diff --git a/go/api/options/zscan_options.go b/go/api/options/zscan_options.go index 54fc4f3259..b831572259 100644 --- a/go/api/options/zscan_options.go +++ b/go/api/options/zscan_options.go @@ -8,7 +8,7 @@ type ZScanOptions struct { noScores bool } -func NewZScanOptionsBuilder() *ZScanOptions { +func NewZScanOptions() *ZScanOptions { return &ZScanOptions{} } @@ -38,7 +38,7 @@ func (options *ZScanOptions) ToArgs() ([]string, error) { args = append(args, baseArgs...) if options.noScores { - args = append(args, NoScores) + args = append(args, NoScoresKeyword) } return args, err } diff --git a/go/api/response_handlers.go b/go/api/response_handlers.go index 95267e2836..bc67b1d4af 100644 --- a/go/api/response_handlers.go +++ b/go/api/response_handlers.go @@ -1223,7 +1223,6 @@ func handleTimeClusterResponse(response *C.struct_CommandResponse) (ClusterValue for nodeName, nodeTimes := range mapData { multiNodeTimes[nodeName] = nodeTimes } - return createClusterMultiValue(multiNodeTimes), nil } diff --git a/go/api/server_management_cluster_commands.go b/go/api/server_management_cluster_commands.go index a4094103da..5c9654547c 100644 --- a/go/api/server_management_cluster_commands.go +++ b/go/api/server_management_cluster_commands.go @@ -12,7 +12,7 @@ import "github.com/valkey-io/valkey-glide/go/api/options" type ServerManagementClusterCommands interface { Info() (map[string]string, error) - InfoWithOptions(options ClusterInfoOptions) (ClusterValue[string], error) + InfoWithOptions(options options.ClusterInfoOptions) (ClusterValue[string], error) TimeWithOptions(routeOption options.RouteOption) (ClusterValue[[]string], error) diff --git a/go/api/server_management_commands.go b/go/api/server_management_commands.go index 48ded7974f..fa8d45f951 100644 --- a/go/api/server_management_commands.go +++ b/go/api/server_management_commands.go @@ -2,6 +2,10 @@ package api +import ( + "github.com/valkey-io/valkey-glide/go/api/options" +) + // ServerManagementCommands supports commands for the "Server Management" group for a standalone client. // // See [valkey.io] for details. @@ -16,7 +20,7 @@ type ServerManagementCommands interface { Info() (string, error) - InfoWithOptions(options InfoOptions) (string, error) + InfoWithOptions(options options.InfoOptions) (string, error) DBSize() (int64, error) diff --git a/go/api/set_commands_test.go b/go/api/set_commands_test.go index 7153b5779b..6abb2633fa 100644 --- a/go/api/set_commands_test.go +++ b/go/api/set_commands_test.go @@ -272,7 +272,7 @@ func ExampleGlideClient_SScanWithOptions() { key := "my_set" client.SAdd(key, []string{"member1", "member2", "item3"}) cursor := "0" - options := options.NewBaseScanOptionsBuilder().SetMatch("mem*") + options := options.NewBaseScanOptions().SetMatch("mem*") result, nextCursor, err := client.SScanWithOptions(key, cursor, options) if err != nil { fmt.Println("Glide example failed with an error: ", err) diff --git a/go/api/sorted_set_commands.go b/go/api/sorted_set_commands.go index 38a61a3991..24326f0c37 100644 --- a/go/api/sorted_set_commands.go +++ b/go/api/sorted_set_commands.go @@ -36,11 +36,11 @@ type SortedSetCommands interface { BZPopMin(keys []string, timeoutSecs float64) (Result[KeyWithMemberAndScore], error) - BZMPop(keys []string, scoreFilter ScoreFilter, timeoutSecs float64) (Result[KeyWithArrayOfMembersAndScores], error) + BZMPop(keys []string, scoreFilter options.ScoreFilter, timeoutSecs float64) (Result[KeyWithArrayOfMembersAndScores], error) BZMPopWithOptions( keys []string, - scoreFilter ScoreFilter, + scoreFilter options.ScoreFilter, timeoutSecs float64, options *options.ZMPopOptions, ) (Result[KeyWithArrayOfMembersAndScores], error) diff --git a/go/api/sorted_set_commands_test.go b/go/api/sorted_set_commands_test.go index a7b75fcf78..409994b0d3 100644 --- a/go/api/sorted_set_commands_test.go +++ b/go/api/sorted_set_commands_test.go @@ -24,7 +24,7 @@ func ExampleGlideClient_ZAdd() { func ExampleGlideClient_ZAddWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function - opts, err := options.NewZAddOptionsBuilder().SetChanged(true) + opts, err := options.NewZAddOptions().SetChanged(true) result, err := client.ZAddWithOptions( "key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0}, @@ -54,7 +54,7 @@ func ExampleGlideClient_ZAddIncr() { func ExampleGlideClient_ZAddIncrWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function - opts, err := options.NewZAddOptionsBuilder().SetChanged(true) // should return an error + opts, err := options.NewZAddOptions().SetChanged(true) // should return an error result, err := client.ZAddIncrWithOptions("key1", "one", 1.0, opts) if err != nil { fmt.Println("Glide example failed with an error: ", err) @@ -332,7 +332,7 @@ func ExampleGlideClient_ZScore() { func ExampleGlideClient_ZCount() { var client *GlideClient = getExampleGlideClient() // example helper function - zCountRange := options.NewZCountRangeBuilder( + zCountRange := options.NewZCountRange( options.NewInclusiveScoreBoundary(2.0), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) @@ -371,8 +371,7 @@ func ExampleGlideClient_ZScanWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function result, err := client.ZAdd("key1", map[string]float64{"one": 1.0, "two": 2.0, "three": 3.0, "four": 4.0}) - resCursor, resCol, err := client.ZScanWithOptions("key1", "0", - options.NewZScanOptionsBuilder().SetMatch("*")) + resCursor, resCol, err := client.ZScanWithOptions("key1", "0", options.NewZScanOptions().SetMatch("*")) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -444,7 +443,7 @@ func ExampleGlideClient_BZMPop() { var client *GlideClient = getExampleGlideClient() // example helper function client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) - result, err := client.BZMPop([]string{"key1"}, MAX, float64(0.5)) + result, err := client.BZMPop([]string{"key1"}, options.MAX, float64(0.5)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } @@ -458,7 +457,7 @@ func ExampleGlideClient_BZMPopWithOptions() { client.ZAdd("key1", map[string]float64{"a": 1.0, "b": 2.0, "c": 3.0, "d": 4.0}) - result, err := client.BZMPopWithOptions([]string{"key1"}, MAX, 0.1, options.NewZMPopOptions().SetCount(2)) + result, err := client.BZMPopWithOptions([]string{"key1"}, options.MAX, 0.1, options.NewZMPopOptions().SetCount(2)) if err != nil { fmt.Println("Glide example failed with an error: ", err) } diff --git a/go/api/string_commands.go b/go/api/string_commands.go index 1641742092..fd83afd1ed 100644 --- a/go/api/string_commands.go +++ b/go/api/string_commands.go @@ -2,6 +2,10 @@ package api +import ( + "github.com/valkey-io/valkey-glide/go/api/options" +) + // Supports commands and transactions for the "String" group of commands for standalone and cluster clients. // // See [valkey.io] for details. @@ -10,13 +14,13 @@ package api type StringCommands interface { Set(key string, value string) (string, error) - SetWithOptions(key string, value string, options *SetOptions) (Result[string], error) + SetWithOptions(key string, value string, options *options.SetOptions) (Result[string], error) Get(key string) (Result[string], error) GetEx(key string) (Result[string], error) - GetExWithOptions(key string, options *GetExOptions) (Result[string], error) + GetExWithOptions(key string, options *options.GetExOptions) (Result[string], error) MSet(keyValueMap map[string]string) (string, error) diff --git a/go/api/string_commands_test.go b/go/api/string_commands_test.go index 5f07d97600..cf7871e6dc 100644 --- a/go/api/string_commands_test.go +++ b/go/api/string_commands_test.go @@ -4,6 +4,8 @@ package api import ( "fmt" + + "github.com/valkey-io/valkey-glide/go/api/options" ) func ExampleGlideClient_Set() { @@ -21,10 +23,10 @@ func ExampleGlideClient_Set() { func ExampleGlideClient_SetWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function - options := NewSetOptionsBuilder(). - SetExpiry(NewExpiryBuilder(). - SetType(Seconds). - SetCount(uint64(5))) + options := options.NewSetOptions(). + SetExpiry(options.NewExpiry(). + SetType(options.Seconds). + SetCount(5)) result, err := client.SetWithOptions("my_key", "my_value", options) if err != nil { fmt.Println("Glide example failed with an error: ", err) @@ -80,10 +82,10 @@ func ExampleGlideClient_GetExWithOptions() { var client *GlideClient = getExampleGlideClient() // example helper function client.Set("my_key", "my_value") - options := NewGetExOptionsBuilder(). - SetExpiry(NewExpiryBuilder(). - SetType(Seconds). - SetCount(uint64(5))) + options := options.NewGetExOptions(). + SetExpiry(options.NewExpiry(). + SetType(options.Seconds). + SetCount(5)) result, err := client.GetExWithOptions("my_key", options) if err != nil { fmt.Println("Glide example failed with an error: ", err) diff --git a/go/integTest/cluster_commands_test.go b/go/integTest/cluster_commands_test.go index d6da52bf18..835825fe92 100644 --- a/go/integTest/cluster_commands_test.go +++ b/go/integTest/cluster_commands_test.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/stretchr/testify/assert" - "github.com/valkey-io/valkey-glide/go/api" "github.com/valkey-io/valkey-glide/go/api/config" "github.com/valkey-io/valkey-glide/go/api/options" ) @@ -59,13 +58,13 @@ func (suite *GlideTestSuite) TestInfoCluster() { } // info with option or with multiple options without route - sections := []api.Section{api.Cpu} + sections := []options.Section{options.Cpu} if suite.serverVersion >= "7.0.0" { - sections = append(sections, api.Memory) + sections = append(sections, options.Memory) } - opts := api.ClusterInfoOptions{ - InfoOptions: &api.InfoOptions{Sections: sections}, - Route: nil, + opts := options.ClusterInfoOptions{ + InfoOptions: &options.InfoOptions{Sections: sections}, + RouteOption: nil, } response, err := client.InfoWithOptions(opts) assert.NoError(t, err) @@ -77,9 +76,9 @@ func (suite *GlideTestSuite) TestInfoCluster() { } // same sections with random route - opts = api.ClusterInfoOptions{ - InfoOptions: &api.InfoOptions{Sections: sections}, - Route: config.RandomRoute.ToPtr(), + opts = options.ClusterInfoOptions{ + InfoOptions: &options.InfoOptions{Sections: sections}, + RouteOption: &options.RouteOption{Route: config.RandomRoute}, } response, err = client.InfoWithOptions(opts) assert.NoError(t, err) @@ -94,9 +93,9 @@ func (suite *GlideTestSuite) TestInfoCluster() { } // default sections, multi node route - opts = api.ClusterInfoOptions{ + opts = options.ClusterInfoOptions{ InfoOptions: nil, - Route: config.AllPrimaries.ToPtr(), + RouteOption: &options.RouteOption{Route: config.AllPrimaries}, } response, err = client.InfoWithOptions(opts) assert.NoError(t, err) @@ -152,7 +151,7 @@ func (suite *GlideTestSuite) TestPingWithOptions_NoRoute() { PingOptions: &options.PingOptions{ Message: "hello", }, - Route: nil, + RouteOption: nil, } result, err := client.PingWithOptions(options) assert.Nil(suite.T(), err) @@ -161,12 +160,11 @@ func (suite *GlideTestSuite) TestPingWithOptions_NoRoute() { func (suite *GlideTestSuite) TestPingWithOptions_WithRoute() { client := suite.defaultClusterClient() - route := config.Route(config.AllNodes) options := options.ClusterPingOptions{ PingOptions: &options.PingOptions{ Message: "hello", }, - Route: &route, + RouteOption: &options.RouteOption{Route: config.AllNodes}, } result, err := client.PingWithOptions(options) assert.Nil(suite.T(), err) @@ -180,7 +178,7 @@ func (suite *GlideTestSuite) TestPingWithOptions_InvalidRoute() { PingOptions: &options.PingOptions{ Message: "hello", }, - Route: &invalidRoute, + RouteOption: &options.RouteOption{Route: invalidRoute}, } result, err := client.PingWithOptions(options) assert.NotNil(suite.T(), err) @@ -202,8 +200,7 @@ func (suite *GlideTestSuite) TestTimeWithoutRoute() { func (suite *GlideTestSuite) TestTimeWithAllNodesRoute() { client := suite.defaultClusterClient() - route := config.Route(config.AllNodes) - options := options.RouteOption{Route: route} + options := options.RouteOption{Route: config.AllNodes} result, err := client.TimeWithOptions(options) assert.NoError(suite.T(), err) assert.NotNil(suite.T(), result) diff --git a/go/integTest/glide_test_suite_test.go b/go/integTest/glide_test_suite_test.go index 197734b541..409f18977f 100644 --- a/go/integTest/glide_test_suite_test.go +++ b/go/integTest/glide_test_suite_test.go @@ -17,6 +17,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/valkey-io/valkey-glide/go/api" "github.com/valkey-io/valkey-glide/go/api/config" + "github.com/valkey-io/valkey-glide/go/api/options" ) type GlideTestSuite struct { @@ -150,7 +151,7 @@ func getServerVersion(suite *GlideTestSuite) string { client, err := api.NewGlideClient(clientConfig) if err == nil && client != nil { defer client.Close() - info, _ := client.InfoWithOptions(api.InfoOptions{Sections: []api.Section{api.Server}}) + info, _ := client.InfoWithOptions(options.InfoOptions{Sections: []options.Section{options.Server}}) return extractServerVersion(suite, info) } } @@ -171,9 +172,9 @@ func getServerVersion(suite *GlideTestSuite) string { defer client.Close() info, _ := client.InfoWithOptions( - api.ClusterInfoOptions{ - InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}}, - Route: config.RandomRoute.ToPtr(), + options.ClusterInfoOptions{ + InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Server}}, + RouteOption: &options.RouteOption{Route: config.RandomRoute}, }, ) return extractServerVersion(suite, info.SingleValue()) diff --git a/go/integTest/json_module_test.go b/go/integTest/json_module_test.go index 7707b043e1..08fc767b48 100644 --- a/go/integTest/json_module_test.go +++ b/go/integTest/json_module_test.go @@ -6,13 +6,16 @@ import ( "strings" "github.com/stretchr/testify/assert" - "github.com/valkey-io/valkey-glide/go/api" + "github.com/valkey-io/valkey-glide/go/api/options" ) func (suite *GlideTestSuite) TestModuleVerifyJsonLoaded() { client := suite.defaultClusterClient() result, err := client.InfoWithOptions( - api.ClusterInfoOptions{InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}}, Route: nil}, + options.ClusterInfoOptions{ + InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Server}}, + RouteOption: nil, + }, ) assert.Nil(suite.T(), err) diff --git a/go/integTest/shared_commands_test.go b/go/integTest/shared_commands_test.go index bb4d3a52b7..27e8cb66ec 100644 --- a/go/integTest/shared_commands_test.go +++ b/go/integTest/shared_commands_test.go @@ -48,7 +48,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_ReturnOldValue() { suite.runWithDefaultClients(func(client api.BaseClient) { suite.verifyOK(client.Set(keyName, initialValue)) - opts := api.NewSetOptionsBuilder().SetReturnOldValue(true) + opts := options.NewSetOptions().SetReturnOldValue(true) result, err := client.SetWithOptions(keyName, anotherValue, opts) assert.Nil(suite.T(), err) @@ -61,7 +61,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfExists_overwrite() { key := uuid.New().String() suite.verifyOK(client.Set(key, initialValue)) - opts := api.NewSetOptionsBuilder().SetConditionalSet(api.OnlyIfExists) + opts := options.NewSetOptions().SetConditionalSet(options.OnlyIfExists) result, err := client.SetWithOptions(key, anotherValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -75,7 +75,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfExists_overwrite() { func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfExists_missingKey() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetConditionalSet(api.OnlyIfExists) + opts := options.NewSetOptions().SetConditionalSet(options.OnlyIfExists) result, err := client.SetWithOptions(key, anotherValue, opts) assert.Nil(suite.T(), err) @@ -86,7 +86,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfExists_missingKey() { func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfDoesNotExist_missingKey() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetConditionalSet(api.OnlyIfDoesNotExist) + opts := options.NewSetOptions().SetConditionalSet(options.OnlyIfDoesNotExist) result, err := client.SetWithOptions(key, anotherValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -100,7 +100,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfDoesNotExist_missingKey() func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfDoesNotExist_existingKey() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetConditionalSet(api.OnlyIfDoesNotExist) + opts := options.NewSetOptions().SetConditionalSet(options.OnlyIfDoesNotExist) suite.verifyOK(client.Set(key, initialValue)) result, err := client.SetWithOptions(key, anotherValue, opts) @@ -118,7 +118,8 @@ func (suite *GlideTestSuite) TestSetWithOptions_OnlyIfDoesNotExist_existingKey() func (suite *GlideTestSuite) TestSetWithOptions_KeepExistingExpiry() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Milliseconds).SetCount(uint64(2000))) + opts := options.NewSetOptions(). + SetExpiry(options.NewExpiry().SetType(options.Milliseconds).SetCount(uint64(2000))) result, err := client.SetWithOptions(key, initialValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -127,7 +128,7 @@ func (suite *GlideTestSuite) TestSetWithOptions_KeepExistingExpiry() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), initialValue, result.Value()) - opts = api.NewSetOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.KeepExisting)) + opts = options.NewSetOptions().SetExpiry(options.NewExpiry().SetType(options.KeepExisting)) result, err = client.SetWithOptions(key, anotherValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -148,7 +149,8 @@ func (suite *GlideTestSuite) TestSetWithOptions_KeepExistingExpiry() { func (suite *GlideTestSuite) TestSetWithOptions_UpdateExistingExpiry() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Milliseconds).SetCount(uint64(100500))) + opts := options.NewSetOptions(). + SetExpiry(options.NewExpiry().SetType(options.Milliseconds).SetCount(uint64(100500))) result, err := client.SetWithOptions(key, initialValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -157,7 +159,8 @@ func (suite *GlideTestSuite) TestSetWithOptions_UpdateExistingExpiry() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), initialValue, result.Value()) - opts = api.NewSetOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Milliseconds).SetCount(uint64(2000))) + opts = options.NewSetOptions(). + SetExpiry(options.NewExpiry().SetType(options.Milliseconds).SetCount(uint64(2000))) result, err = client.SetWithOptions(key, anotherValue, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result.Value()) @@ -195,7 +198,8 @@ func (suite *GlideTestSuite) TestGetExWithOptions_PersistKey() { key := uuid.New().String() suite.verifyOK(client.Set(key, initialValue)) - opts := api.NewGetExOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Milliseconds).SetCount(uint64(2000))) + opts := options.NewGetExOptions(). + SetExpiry(options.NewExpiry().SetType(options.Milliseconds).SetCount(uint64(2000))) result, err := client.GetExWithOptions(key, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), initialValue, result.Value()) @@ -206,7 +210,7 @@ func (suite *GlideTestSuite) TestGetExWithOptions_PersistKey() { time.Sleep(1000 * time.Millisecond) - opts = api.NewGetExOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Persist)) + opts = options.NewGetExOptions().SetExpiry(options.NewExpiry().SetType(options.Persist)) result, err = client.GetExWithOptions(key, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), initialValue, result.Value()) @@ -218,7 +222,8 @@ func (suite *GlideTestSuite) TestGetExWithOptions_UpdateExpiry() { key := uuid.New().String() suite.verifyOK(client.Set(key, initialValue)) - opts := api.NewGetExOptionsBuilder().SetExpiry(api.NewExpiryBuilder().SetType(api.Milliseconds).SetCount(uint64(2000))) + opts := options.NewGetExOptions(). + SetExpiry(options.NewExpiry().SetType(options.Milliseconds).SetCount(uint64(2000))) result, err := client.GetExWithOptions(key, opts) assert.Nil(suite.T(), err) assert.Equal(suite.T(), initialValue, result.Value()) @@ -238,7 +243,7 @@ func (suite *GlideTestSuite) TestGetExWithOptions_UpdateExpiry() { func (suite *GlideTestSuite) TestSetWithOptions_ReturnOldValue_nonExistentKey() { suite.runWithDefaultClients(func(client api.BaseClient) { key := uuid.New().String() - opts := api.NewSetOptionsBuilder().SetReturnOldValue(true) + opts := options.NewSetOptions().SetReturnOldValue(true) result, err := client.SetWithOptions(key, anotherValue, opts) @@ -1141,7 +1146,7 @@ func (suite *GlideTestSuite) TestHScan() { assert.True(t, isSubset(resultKeys, keysList) && isSubset(keysList, resultKeys)) assert.True(t, isSubset(resultValues, valuesList) && isSubset(valuesList, resultValues)) - opts := options.NewHashScanOptionsBuilder().SetMatch("a") + opts := options.NewHashScanOptions().SetMatch("a") resCursor, resCollection, _ = client.HScanWithOptions(key1, initialCursor, opts) assert.Equal(t, initialCursor, resCursor) assert.Equal(t, len(resCollection), 2) @@ -1197,28 +1202,28 @@ func (suite *GlideTestSuite) TestHScan() { assert.True(t, isSubset(numberValuesList, secondResultAllValues)) // Test match pattern - opts = options.NewHashScanOptionsBuilder().SetMatch("*") + opts = options.NewHashScanOptions().SetMatch("*") resCursor, resCollection, _ = client.HScanWithOptions(key1, initialCursor, opts) resCursorInt, _ := strconv.Atoi(resCursor) assert.True(t, resCursorInt >= 0) assert.True(t, int(len(resCollection)) >= defaultCount) // Test count - opts = options.NewHashScanOptionsBuilder().SetCount(int64(20)) + opts = options.NewHashScanOptions().SetCount(int64(20)) resCursor, resCollection, _ = client.HScanWithOptions(key1, initialCursor, opts) resCursorInt, _ = strconv.Atoi(resCursor) assert.True(t, resCursorInt >= 0) assert.True(t, len(resCollection) >= 20) // Test count with match returns a non-empty list - opts = options.NewHashScanOptionsBuilder().SetMatch("1*").SetCount(int64(20)) + opts = options.NewHashScanOptions().SetMatch("1*").SetCount(int64(20)) resCursor, resCollection, _ = client.HScanWithOptions(key1, initialCursor, opts) resCursorInt, _ = strconv.Atoi(resCursor) assert.True(t, resCursorInt >= 0) assert.True(t, len(resCollection) >= 0) if suite.serverVersion >= "8.0.0" { - opts = options.NewHashScanOptionsBuilder().SetNoValue(true) + opts = options.NewHashScanOptions().SetNoValue(true) resCursor, resCollection, _ = client.HScanWithOptions(key1, initialCursor, opts) resCursorInt, _ = strconv.Atoi(resCursor) assert.True(t, resCursorInt >= 0) @@ -1240,12 +1245,12 @@ func (suite *GlideTestSuite) TestHScan() { assert.NotEmpty(t, err) // Check if Non-hash key throws an error when HSCAN called with options. - opts = options.NewHashScanOptionsBuilder().SetMatch("test").SetCount(int64(1)) + opts = options.NewHashScanOptions().SetMatch("test").SetCount(int64(1)) _, _, err = client.HScanWithOptions(key2, initialCursor, opts) assert.NotEmpty(t, err) // Check if a negative cursor value throws an error. - opts = options.NewHashScanOptionsBuilder().SetCount(int64(-1)) + opts = options.NewHashScanOptions().SetCount(int64(-1)) _, _, err = client.HScanWithOptions(key1, initialCursor, opts) assert.NotEmpty(t, err) }) @@ -1383,7 +1388,7 @@ func (suite *GlideTestSuite) TestLPos_withAndWithoutOptions() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(0), res2.Value()) - res3, err := client.LPosWithOptions(key, "b", api.NewLPosOptionsBuilder().SetRank(2)) + res3, err := client.LPosWithOptions(key, "b", options.NewLPosOptions().SetRank(2)) assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(5), res3.Value()) @@ -1393,7 +1398,7 @@ func (suite *GlideTestSuite) TestLPos_withAndWithoutOptions() { assert.Equal(suite.T(), api.CreateNilInt64Result(), res4) // reverse traversal - res5, err := client.LPosWithOptions(key, "b", api.NewLPosOptionsBuilder().SetRank(-2)) + res5, err := client.LPosWithOptions(key, "b", options.NewLPosOptions().SetRank(-2)) assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(2), res5.Value()) @@ -1401,7 +1406,7 @@ func (suite *GlideTestSuite) TestLPos_withAndWithoutOptions() { res6, err := client.LPosWithOptions( key, "a", - api.NewLPosOptionsBuilder().SetRank(1).SetMaxLen(0), + options.NewLPosOptions().SetRank(1).SetMaxLen(0), ) assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(0), res6.Value()) @@ -1410,19 +1415,19 @@ func (suite *GlideTestSuite) TestLPos_withAndWithoutOptions() { res7, err := client.LPosWithOptions( key, "c", - api.NewLPosOptionsBuilder().SetRank(1).SetMaxLen(2), + options.NewLPosOptions().SetRank(1).SetMaxLen(2), ) assert.Nil(suite.T(), err) assert.Equal(suite.T(), api.CreateNilInt64Result(), res7) // invalid rank value - res8, err := client.LPosWithOptions(key, "a", api.NewLPosOptionsBuilder().SetRank(0)) + res8, err := client.LPosWithOptions(key, "a", options.NewLPosOptions().SetRank(0)) assert.Equal(suite.T(), api.CreateNilInt64Result(), res8) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) // invalid maxlen value - res9, err := client.LPosWithOptions(key, "a", api.NewLPosOptionsBuilder().SetMaxLen(-1)) + res9, err := client.LPosWithOptions(key, "a", options.NewLPosOptions().SetMaxLen(-1)) assert.Equal(suite.T(), api.CreateNilInt64Result(), res9) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -1487,16 +1492,16 @@ func (suite *GlideTestSuite) TestLPosCount_withOptions() { assert.Equal(suite.T(), int64(6), res1) assert.Nil(suite.T(), err) - res2, err := client.LPosCountWithOptions(key, "a", int64(0), api.NewLPosOptionsBuilder().SetRank(1)) + res2, err := client.LPosCountWithOptions(key, "a", int64(0), options.NewLPosOptions().SetRank(1)) assert.Equal(suite.T(), []int64{0, 1, 4}, res2) assert.Nil(suite.T(), err) - res3, err := client.LPosCountWithOptions(key, "a", int64(0), api.NewLPosOptionsBuilder().SetRank(2)) + res3, err := client.LPosCountWithOptions(key, "a", int64(0), options.NewLPosOptions().SetRank(2)) assert.Equal(suite.T(), []int64{1, 4}, res3) assert.Nil(suite.T(), err) // reverse traversal - res4, err := client.LPosCountWithOptions(key, "a", int64(0), api.NewLPosOptionsBuilder().SetRank(-1)) + res4, err := client.LPosCountWithOptions(key, "a", int64(0), options.NewLPosOptions().SetRank(-1)) assert.Equal(suite.T(), []int64{4, 1, 0}, res4) assert.Nil(suite.T(), err) }) @@ -2335,7 +2340,7 @@ func (suite *GlideTestSuite) TestSScan() { assert.Equal(t, len(charMembers), len(resCollection)) assert.True(t, isSubset(resCollection, charMembers)) - opts := options.NewBaseScanOptionsBuilder().SetMatch("a") + opts := options.NewBaseScanOptions().SetMatch("a") resCursor, resCollection, err = client.SScanWithOptions(key1, initialCursor, opts) assert.NoError(t, err) assert.Equal(t, initialCursor, resCursor) @@ -2363,21 +2368,21 @@ func (suite *GlideTestSuite) TestSScan() { assert.True(t, isSubset(charMembers, resultCollection)) // test match pattern - opts = options.NewBaseScanOptionsBuilder().SetMatch("*") + opts = options.NewBaseScanOptions().SetMatch("*") resCursor, resCollection, err = client.SScanWithOptions(key1, initialCursor, opts) assert.NoError(t, err) assert.NotEqual(t, initialCursor, resCursor) assert.GreaterOrEqual(t, len(resCollection), defaultCount) // test count - opts = options.NewBaseScanOptionsBuilder().SetCount(20) + opts = options.NewBaseScanOptions().SetCount(20) resCursor, resCollection, err = client.SScanWithOptions(key1, initialCursor, opts) assert.NoError(t, err) assert.NotEqual(t, initialCursor, resCursor) assert.GreaterOrEqual(t, len(resCollection), 20) // test count with match, returns a non-empty array - opts = options.NewBaseScanOptionsBuilder().SetMatch("1*").SetCount(20) + opts = options.NewBaseScanOptions().SetMatch("1*").SetCount(20) resCursor, resCollection, err = client.SScanWithOptions(key1, initialCursor, opts) assert.NoError(t, err) assert.NotEqual(t, initialCursor, resCursor) @@ -2598,11 +2603,11 @@ func (suite *GlideTestSuite) TestLInsert() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(4), res1) - res2, err := client.LInsert(key, api.Before, "value2", "value1.5") + res2, err := client.LInsert(key, options.Before, "value2", "value1.5") assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(5), res2) - res3, err := client.LInsert(key, api.After, "value3", "value3.5") + res3, err := client.LInsert(key, options.After, "value3", "value3.5") assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(6), res3) @@ -2610,18 +2615,18 @@ func (suite *GlideTestSuite) TestLInsert() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), []string{"value1", "value1.5", "value2", "value3", "value3.5", "value4"}, res4) - res5, err := client.LInsert("non_existing_key", api.Before, "pivot", "elem") + res5, err := client.LInsert("non_existing_key", options.Before, "pivot", "elem") assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(0), res5) - res6, err := client.LInsert(key, api.Before, "value5", "value6") + res6, err := client.LInsert(key, options.Before, "value5", "value6") assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(-1), res6) key2 := uuid.NewString() suite.verifyOK(client.Set(key2, "value")) - res7, err := client.LInsert(key2, api.Before, "value5", "value6") + res7, err := client.LInsert(key2, options.Before, "value5", "value6") assert.Equal(suite.T(), int64(0), res7) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -2771,11 +2776,11 @@ func (suite *GlideTestSuite) TestLMPopAndLMPopCount() { key2 := "{key}-2" + uuid.NewString() key3 := "{key}-3" + uuid.NewString() - res1, err := client.LMPop([]string{key1}, api.Left) + res1, err := client.LMPop([]string{key1}, options.Left) assert.Nil(suite.T(), err) assert.Nil(suite.T(), res1) - res2, err := client.LMPopCount([]string{key1}, api.Left, int64(1)) + res2, err := client.LMPopCount([]string{key1}, options.Left, int64(1)) assert.Nil(suite.T(), err) assert.Nil(suite.T(), res2) @@ -2786,7 +2791,7 @@ func (suite *GlideTestSuite) TestLMPopAndLMPopCount() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(5), res4) - res5, err := client.LMPop([]string{key1}, api.Left) + res5, err := client.LMPop([]string{key1}, options.Left) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2794,7 +2799,7 @@ func (suite *GlideTestSuite) TestLMPopAndLMPopCount() { res5, ) - res6, err := client.LMPopCount([]string{key2, key1}, api.Right, int64(2)) + res6, err := client.LMPopCount([]string{key2, key1}, options.Right, int64(2)) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2806,7 +2811,7 @@ func (suite *GlideTestSuite) TestLMPopAndLMPopCount() { suite.verifyOK(client.Set(key3, "value")) - res7, err := client.LMPop([]string{key3}, api.Left) + res7, err := client.LMPop([]string{key3}, options.Left) assert.Nil(suite.T(), res7) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -2827,11 +2832,11 @@ func (suite *GlideTestSuite) TestBLMPopAndBLMPopCount() { key2 := "{key}-2" + uuid.NewString() key3 := "{key}-3" + uuid.NewString() - res1, err := client.BLMPop([]string{key1}, api.Left, float64(0.1)) + res1, err := client.BLMPop([]string{key1}, options.Left, float64(0.1)) assert.Nil(suite.T(), err) assert.Nil(suite.T(), res1) - res2, err := client.BLMPopCount([]string{key1}, api.Left, int64(1), float64(0.1)) + res2, err := client.BLMPopCount([]string{key1}, options.Left, int64(1), float64(0.1)) assert.Nil(suite.T(), err) assert.Nil(suite.T(), res2) @@ -2842,7 +2847,7 @@ func (suite *GlideTestSuite) TestBLMPopAndBLMPopCount() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(5), res4) - res5, err := client.BLMPop([]string{key1}, api.Left, float64(0.1)) + res5, err := client.BLMPop([]string{key1}, options.Left, float64(0.1)) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2850,7 +2855,7 @@ func (suite *GlideTestSuite) TestBLMPopAndBLMPopCount() { res5, ) - res6, err := client.BLMPopCount([]string{key2, key1}, api.Right, int64(2), float64(0.1)) + res6, err := client.BLMPopCount([]string{key2, key1}, options.Right, int64(2), float64(0.1)) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2862,7 +2867,7 @@ func (suite *GlideTestSuite) TestBLMPopAndBLMPopCount() { suite.verifyOK(client.Set(key3, "value")) - res7, err := client.BLMPop([]string{key3}, api.Left, float64(0.1)) + res7, err := client.BLMPop([]string{key3}, options.Left, float64(0.1)) assert.Nil(suite.T(), res7) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -2878,7 +2883,7 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() { key2 := "{key}-2" + uuid.NewString() key3 := "{key}-3" + uuid.NewString() - res1, err := client.BZMPop([]string{key1}, api.MIN, float64(0.1)) + res1, err := client.BZMPop([]string{key1}, options.MIN, float64(0.1)) assert.Nil(suite.T(), err) assert.True(suite.T(), res1.IsNil()) @@ -2896,7 +2901,12 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() { assert.Equal(suite.T(), int64(3), res4) // Try to pop the top 2 elements from key1 - res5, err := client.BZMPopWithOptions([]string{key1}, api.MAX, float64(0.1), options.NewZMPopOptions().SetCount(2)) + res5, err := client.BZMPopWithOptions( + []string{key1}, + options.MAX, + float64(0.1), + options.NewZMPopOptions().SetCount(2), + ) assert.Nil(suite.T(), err) assert.Equal(suite.T(), key1, res5.Value().Key) assert.ElementsMatch( @@ -2909,7 +2919,7 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() { ) // Try to pop the minimum value from key2 - res6, err := client.BZMPop([]string{key2}, api.MIN, float64(0.1)) + res6, err := client.BZMPop([]string{key2}, options.MIN, float64(0.1)) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2925,7 +2935,7 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() { ) // Pop the minimum value from multiple keys - res7, err := client.BZMPop([]string{key1, key2}, api.MIN, float64(0.1)) + res7, err := client.BZMPop([]string{key1, key2}, options.MIN, float64(0.1)) assert.Nil(suite.T(), err) assert.Equal( suite.T(), @@ -2943,7 +2953,7 @@ func (suite *GlideTestSuite) TestBZMPopAndBZMPopWithOptions() { suite.verifyOK(client.Set(key3, "value")) // Popping a non-existent value in key3 - res8, err := client.BZMPop([]string{key3}, api.MIN, float64(0.1)) + res8, err := client.BZMPop([]string{key3}, options.MIN, float64(0.1)) assert.True(suite.T(), res8.IsNil()) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -2991,7 +3001,7 @@ func (suite *GlideTestSuite) TestLMove() { nonExistentKey := "{key}-3" + uuid.NewString() nonListKey := "{key}-4" + uuid.NewString() - res1, err := client.LMove(key1, key2, api.Left, api.Right) + res1, err := client.LMove(key1, key2, options.Left, options.Right) assert.Equal(suite.T(), api.CreateNilStringResult(), res1) assert.Nil(suite.T(), err) @@ -3000,7 +3010,7 @@ func (suite *GlideTestSuite) TestLMove() { assert.Equal(suite.T(), int64(4), res2) // only source exists, only source elements gets popped, creates a list at nonExistingKey - res3, err := client.LMove(key1, nonExistentKey, api.Right, api.Left) + res3, err := client.LMove(key1, nonExistentKey, options.Right, options.Left) assert.Equal(suite.T(), "four", res3.Value()) assert.Nil(suite.T(), err) @@ -3009,7 +3019,7 @@ func (suite *GlideTestSuite) TestLMove() { assert.Equal(suite.T(), []string{"one", "two", "three"}, res4) // source and destination are the same, performing list rotation, "one" gets popped and added back - res5, err := client.LMove(key1, key1, api.Left, api.Left) + res5, err := client.LMove(key1, key1, options.Left, options.Left) assert.Equal(suite.T(), "one", res5.Value()) assert.Nil(suite.T(), err) @@ -3021,7 +3031,7 @@ func (suite *GlideTestSuite) TestLMove() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(3), res7) - res8, err := client.LMove(key1, key2, api.Right, api.Left) + res8, err := client.LMove(key1, key2, options.Right, options.Left) assert.Equal(suite.T(), "three", res8.Value()) assert.Nil(suite.T(), err) @@ -3035,7 +3045,7 @@ func (suite *GlideTestSuite) TestLMove() { // source exists but is not a list type key suite.verifyOK(client.Set(nonListKey, "value")) - res11, err := client.LMove(nonListKey, key1, api.Left, api.Left) + res11, err := client.LMove(nonListKey, key1, options.Left, options.Left) assert.Equal(suite.T(), api.CreateNilStringResult(), res11) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -3043,7 +3053,7 @@ func (suite *GlideTestSuite) TestLMove() { // destination exists but is not a list type key suite.verifyOK(client.Set(nonListKey, "value")) - res12, err := client.LMove(key1, nonListKey, api.Left, api.Left) + res12, err := client.LMove(key1, nonListKey, options.Left, options.Left) assert.Equal(suite.T(), api.CreateNilStringResult(), res12) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -3113,7 +3123,7 @@ func (suite *GlideTestSuite) TestExpireWithOptions_HasNoExpiry() { suite.verifyOK(client.Set(key, value)) - result, err := client.ExpireWithOptions(key, 2, api.HasNoExpiry) + result, err := client.ExpireWithOptions(key, 2, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), result) @@ -3123,7 +3133,7 @@ func (suite *GlideTestSuite) TestExpireWithOptions_HasNoExpiry() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), "", resultGet.Value()) - result, err = client.ExpireWithOptions(key, 1, api.HasNoExpiry) + result, err = client.ExpireWithOptions(key, 1, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.False(suite.T(), result) }) @@ -3137,11 +3147,11 @@ func (suite *GlideTestSuite) TestExpireWithOptions_HasExistingExpiry() { suite.verifyOK(client.Set(key, value)) - resexp, err := client.ExpireWithOptions(key, 20, api.HasNoExpiry) + resexp, err := client.ExpireWithOptions(key, 20, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resexp) - resultExpire, err := client.ExpireWithOptions(key, 1, api.HasExistingExpiry) + resultExpire, err := client.ExpireWithOptions(key, 1, options.HasExistingExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) @@ -3161,11 +3171,11 @@ func (suite *GlideTestSuite) TestExpireWithOptions_NewExpiryGreaterThanCurrent() value := uuid.New().String() suite.verifyOK(client.Set(key, value)) - resultExpire, err := client.ExpireWithOptions(key, 2, api.HasNoExpiry) + resultExpire, err := client.ExpireWithOptions(key, 2, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) - resultExpire, err = client.ExpireWithOptions(key, 5, api.NewExpiryGreaterThanCurrent) + resultExpire, err = client.ExpireWithOptions(key, 5, options.NewExpiryGreaterThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) time.Sleep(6 * time.Second) @@ -3183,16 +3193,16 @@ func (suite *GlideTestSuite) TestExpireWithOptions_NewExpiryLessThanCurrent() { suite.verifyOK(client.Set(key, value)) - resultExpire, err := client.ExpireWithOptions(key, 10, api.HasNoExpiry) + resultExpire, err := client.ExpireWithOptions(key, 10, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) - resultExpire, err = client.ExpireWithOptions(key, 5, api.NewExpiryLessThanCurrent) + resultExpire, err = client.ExpireWithOptions(key, 5, options.NewExpiryLessThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) - resultExpire, err = client.ExpireWithOptions(key, 15, api.NewExpiryGreaterThanCurrent) + resultExpire, err = client.ExpireWithOptions(key, 15, options.NewExpiryGreaterThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) @@ -3213,13 +3223,13 @@ func (suite *GlideTestSuite) TestExpireAtWithOptions_HasNoExpiry() { futureTimestamp := time.Now().Add(10 * time.Second).Unix() - resultExpire, err := client.ExpireAtWithOptions(key, futureTimestamp, api.HasNoExpiry) + resultExpire, err := client.ExpireAtWithOptions(key, futureTimestamp, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpire) resultExpireAt, err := client.ExpireAt(key, futureTimestamp) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireAt) - resultExpireWithOptions, err := client.ExpireAtWithOptions(key, futureTimestamp+10, api.HasNoExpiry) + resultExpireWithOptions, err := client.ExpireAtWithOptions(key, futureTimestamp+10, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.False(suite.T(), resultExpireWithOptions) }) @@ -3237,7 +3247,7 @@ func (suite *GlideTestSuite) TestExpireAtWithOptions_HasExistingExpiry() { assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireAt) - resultExpireWithOptions, err := client.ExpireAtWithOptions(key, futureTimestamp+10, api.HasExistingExpiry) + resultExpireWithOptions, err := client.ExpireAtWithOptions(key, futureTimestamp+10, options.HasExistingExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) }) @@ -3257,7 +3267,11 @@ func (suite *GlideTestSuite) TestExpireAtWithOptions_NewExpiryGreaterThanCurrent assert.True(suite.T(), resultExpireAt) newFutureTimestamp := time.Now().Add(20 * time.Second).Unix() - resultExpireWithOptions, err := client.ExpireAtWithOptions(key, newFutureTimestamp, api.NewExpiryGreaterThanCurrent) + resultExpireWithOptions, err := client.ExpireAtWithOptions( + key, + newFutureTimestamp, + options.NewExpiryGreaterThanCurrent, + ) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) }) @@ -3277,7 +3291,7 @@ func (suite *GlideTestSuite) TestExpireAtWithOptions_NewExpiryLessThanCurrent() assert.True(suite.T(), resultExpireAt) newFutureTimestamp := time.Now().Add(5 * time.Second).Unix() - resultExpireWithOptions, err := client.ExpireAtWithOptions(key, newFutureTimestamp, api.NewExpiryLessThanCurrent) + resultExpireWithOptions, err := client.ExpireAtWithOptions(key, newFutureTimestamp, options.NewExpiryLessThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3322,7 +3336,7 @@ func (suite *GlideTestSuite) TestPExpireWithOptions_HasExistingExpiry() { newExpire := 1000 - resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), api.HasExistingExpiry) + resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), options.HasExistingExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3343,7 +3357,7 @@ func (suite *GlideTestSuite) TestPExpireWithOptions_HasNoExpiry() { newExpire := 500 - resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), api.HasNoExpiry) + resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3369,7 +3383,7 @@ func (suite *GlideTestSuite) TestPExpireWithOptions_NewExpiryGreaterThanCurrent( newExpire := 1000 - resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), api.NewExpiryGreaterThanCurrent) + resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), options.NewExpiryGreaterThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3395,7 +3409,7 @@ func (suite *GlideTestSuite) TestPExpireWithOptions_NewExpiryLessThanCurrent() { newExpire := 200 - resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), api.NewExpiryLessThanCurrent) + resultExpireWithOptions, err := client.PExpireWithOptions(key, int64(newExpire), options.NewExpiryLessThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3435,7 +3449,7 @@ func (suite *GlideTestSuite) TestPExpireAtWithOptions_HasNoExpiry() { suite.verifyOK(client.Set(key, value)) timestamp := time.Now().Unix() * 1000 - result, err := client.PExpireAtWithOptions(key, timestamp, api.HasNoExpiry) + result, err := client.PExpireAtWithOptions(key, timestamp, options.HasNoExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), result) @@ -3460,7 +3474,7 @@ func (suite *GlideTestSuite) TestPExpireAtWithOptions_HasExistingExpiry() { assert.True(suite.T(), resultExpire) newExpire := time.Now().Unix()*1000 + 1000 - resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, api.HasExistingExpiry) + resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, options.HasExistingExpiry) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3486,7 +3500,7 @@ func (suite *GlideTestSuite) TestPExpireAtWithOptions_NewExpiryGreaterThanCurren newExpire := time.Now().UnixMilli() + 2000 - resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, api.NewExpiryGreaterThanCurrent) + resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, options.NewExpiryGreaterThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3512,7 +3526,7 @@ func (suite *GlideTestSuite) TestPExpireAtWithOptions_NewExpiryLessThanCurrent() newExpire := time.Now().Unix()*1000 + 500 - resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, api.NewExpiryLessThanCurrent) + resultExpireWithOptions, err := client.PExpireAtWithOptions(key, newExpire, options.NewExpiryLessThanCurrent) assert.Nil(suite.T(), err) assert.True(suite.T(), resultExpireWithOptions) @@ -3985,7 +3999,7 @@ func (suite *GlideTestSuite) TestBLMove() { nonExistentKey := "{key}-3" + uuid.NewString() nonListKey := "{key}-4" + uuid.NewString() - res1, err := client.BLMove(key1, key2, api.Left, api.Right, float64(0.1)) + res1, err := client.BLMove(key1, key2, options.Left, options.Right, float64(0.1)) assert.Equal(suite.T(), api.CreateNilStringResult(), res1) assert.Nil(suite.T(), err) @@ -3994,7 +4008,7 @@ func (suite *GlideTestSuite) TestBLMove() { assert.Equal(suite.T(), int64(4), res2) // only source exists, only source elements gets popped, creates a list at nonExistingKey - res3, err := client.BLMove(key1, nonExistentKey, api.Right, api.Left, float64(0.1)) + res3, err := client.BLMove(key1, nonExistentKey, options.Right, options.Left, float64(0.1)) assert.Equal(suite.T(), "four", res3.Value()) assert.Nil(suite.T(), err) @@ -4003,7 +4017,7 @@ func (suite *GlideTestSuite) TestBLMove() { assert.Equal(suite.T(), []string{"one", "two", "three"}, res4) // source and destination are the same, performing list rotation, "one" gets popped and added back - res5, err := client.BLMove(key1, key1, api.Left, api.Left, float64(0.1)) + res5, err := client.BLMove(key1, key1, options.Left, options.Left, float64(0.1)) assert.Equal(suite.T(), "one", res5.Value()) assert.Nil(suite.T(), err) @@ -4015,7 +4029,7 @@ func (suite *GlideTestSuite) TestBLMove() { assert.Nil(suite.T(), err) assert.Equal(suite.T(), int64(3), res7) - res8, err := client.BLMove(key1, key2, api.Right, api.Left, float64(0.1)) + res8, err := client.BLMove(key1, key2, options.Right, options.Left, float64(0.1)) assert.Equal(suite.T(), "three", res8.Value()) assert.Nil(suite.T(), err) @@ -4030,7 +4044,7 @@ func (suite *GlideTestSuite) TestBLMove() { // source exists but is not a list type key suite.verifyOK(client.Set(nonListKey, "value")) - res11, err := client.BLMove(nonListKey, key1, api.Left, api.Left, float64(0.1)) + res11, err := client.BLMove(nonListKey, key1, options.Left, options.Left, float64(0.1)) assert.Equal(suite.T(), api.CreateNilStringResult(), res11) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -4038,7 +4052,7 @@ func (suite *GlideTestSuite) TestBLMove() { // destination exists but is not a list type key suite.verifyOK(client.Set(nonListKey, "value")) - res12, err := client.BLMove(key1, nonListKey, api.Left, api.Left, float64(0.1)) + res12, err := client.BLMove(key1, nonListKey, options.Left, options.Left, float64(0.1)) assert.Equal(suite.T(), api.CreateNilStringResult(), res12) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -4505,7 +4519,11 @@ func (suite *GlideTestSuite) TestXRead() { assert.Nil(suite.T(), err) assert.False(suite.T(), res.IsNil()) - res, err = client.XAddWithOptions(key2, [][]string{{"k2_field1", "k2_value1"}}, options.NewXAddOptions().SetId("2-0")) + res, err = client.XAddWithOptions( + key2, + [][]string{{"k2_field1", "k2_value1"}}, + options.NewXAddOptions().SetId("2-0"), + ) assert.Nil(suite.T(), err) assert.False(suite.T(), res.IsNil()) @@ -4542,7 +4560,10 @@ func (suite *GlideTestSuite) TestXRead() { WithAddress(&suite.clusterHosts[0]). WithUseTLS(suite.tls)) } - read, err = testClient.XReadWithOptions(map[string]string{key1: "0-1"}, options.NewXReadOptions().SetBlock(1000)) + read, err = testClient.XReadWithOptions( + map[string]string{key1: "0-1"}, + options.NewXReadOptions().SetBlock(1000), + ) assert.Nil(suite.T(), err) assert.Nil(suite.T(), read) @@ -4686,8 +4707,8 @@ func (suite *GlideTestSuite) TestZAddAndZAddIncr() { assert.IsType(suite.T(), &errors.RequestError{}, err) // with NX & XX - onlyIfExistsOpts := options.NewZAddOptionsBuilder().SetConditionalChange(options.OnlyIfExists) - onlyIfDoesNotExistOpts := options.NewZAddOptionsBuilder().SetConditionalChange(options.OnlyIfDoesNotExist) + onlyIfExistsOpts := options.NewZAddOptions().SetConditionalChange(options.OnlyIfExists) + onlyIfDoesNotExistOpts := options.NewZAddOptions().SetConditionalChange(options.OnlyIfDoesNotExist) res, err = client.ZAddWithOptions(key3, membersScoreMap, onlyIfExistsOpts) assert.Nil(suite.T(), err) @@ -4718,10 +4739,10 @@ func (suite *GlideTestSuite) TestZAddAndZAddIncr() { membersScoreMap2["one"] = 10.0 - gtOpts := options.NewZAddOptionsBuilder().SetUpdateOptions(options.ScoreGreaterThanCurrent) - ltOpts := options.NewZAddOptionsBuilder().SetUpdateOptions(options.ScoreLessThanCurrent) - gtOptsChanged, _ := options.NewZAddOptionsBuilder().SetUpdateOptions(options.ScoreGreaterThanCurrent).SetChanged(true) - ltOptsChanged, _ := options.NewZAddOptionsBuilder().SetUpdateOptions(options.ScoreLessThanCurrent).SetChanged(true) + gtOpts := options.NewZAddOptions().SetUpdateOptions(options.ScoreGreaterThanCurrent) + ltOpts := options.NewZAddOptions().SetUpdateOptions(options.ScoreLessThanCurrent) + gtOptsChanged, _ := options.NewZAddOptions().SetUpdateOptions(options.ScoreGreaterThanCurrent).SetChanged(true) + ltOptsChanged, _ := options.NewZAddOptions().SetUpdateOptions(options.ScoreLessThanCurrent).SetChanged(true) res, err = client.ZAddWithOptions(key4, membersScoreMap2, gtOptsChanged) assert.Nil(suite.T(), err) @@ -5356,14 +5377,14 @@ func (suite *GlideTestSuite) TestZCount() { assert.Equal(t, int64(3), res1) // In range negative to positive infinity. - zCountRange := options.NewZCountRangeBuilder( + zCountRange := options.NewZCountRange( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) zCountResult, err := client.ZCount(key1, zCountRange) assert.Nil(t, err) assert.Equal(t, int64(3), zCountResult) - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewInclusiveScoreBoundary(math.Inf(-1)), options.NewInclusiveScoreBoundary(math.Inf(+1)), ) @@ -5372,7 +5393,7 @@ func (suite *GlideTestSuite) TestZCount() { assert.Equal(t, int64(3), zCountResult) // In range 1 (exclusive) to 3 (inclusive) - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewScoreBoundary(1, false), options.NewScoreBoundary(3, true), ) @@ -5381,7 +5402,7 @@ func (suite *GlideTestSuite) TestZCount() { assert.Equal(t, int64(2), zCountResult) // In range negative infinity to 3 (inclusive) - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewScoreBoundary(3, true), ) @@ -5390,7 +5411,7 @@ func (suite *GlideTestSuite) TestZCount() { assert.Equal(t, int64(3), zCountResult) // Incorrect range start > end - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewInfiniteScoreBoundary(options.PositiveInfinity), options.NewInclusiveScoreBoundary(3), ) @@ -5399,7 +5420,7 @@ func (suite *GlideTestSuite) TestZCount() { assert.Equal(t, int64(0), zCountResult) // Non-existing key - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) @@ -5410,7 +5431,7 @@ func (suite *GlideTestSuite) TestZCount() { // Key exists, but it is not a set setResult, _ := client.Set(key2, "value") assert.Equal(t, setResult, "OK") - zCountRange = options.NewZCountRangeBuilder( + zCountRange = options.NewZCountRange( options.NewInfiniteScoreBoundary(options.NegativeInfinity), options.NewInfiniteScoreBoundary(options.PositiveInfinity), ) @@ -5533,7 +5554,7 @@ func (suite *GlideTestSuite) TestZScan() { // Scores come back as integers converted to a string when the fraction is zero. assert.True(suite.T(), isSubset(charMapValues, resultValueSet)) - opts := options.NewZScanOptionsBuilder().SetMatch("a") + opts := options.NewZScanOptions().SetMatch("a") resCursor, resCollection, err = client.ZScanWithOptions(key1, initialCursor, opts) assert.NoError(suite.T(), err) assert.Equal(suite.T(), initialCursor, resCursor) @@ -5568,21 +5589,21 @@ func (suite *GlideTestSuite) TestZScan() { assert.True(suite.T(), isSubset(numMembers, resKeys)) // Test match pattern - opts = options.NewZScanOptionsBuilder().SetMatch("*") + opts = options.NewZScanOptions().SetMatch("*") resCursor, resCollection, err = client.ZScanWithOptions(key1, initialCursor, opts) assert.NoError(suite.T(), err) assert.NotEqual(suite.T(), initialCursor, resCursor) assert.GreaterOrEqual(suite.T(), len(resCollection), defaultCount) // test count - opts = options.NewZScanOptionsBuilder().SetCount(20) + opts = options.NewZScanOptions().SetCount(20) resCursor, resCollection, err = client.ZScanWithOptions(key1, initialCursor, opts) assert.NoError(suite.T(), err) assert.NotEqual(suite.T(), initialCursor, resCursor) assert.GreaterOrEqual(suite.T(), len(resCollection), 20) // test count with match, returns a non-empty array - opts = options.NewZScanOptionsBuilder().SetMatch("1*").SetCount(20) + opts = options.NewZScanOptions().SetMatch("1*").SetCount(20) resCursor, resCollection, err = client.ZScanWithOptions(key1, initialCursor, opts) assert.NoError(suite.T(), err) assert.NotEqual(suite.T(), initialCursor, resCursor) @@ -5590,7 +5611,7 @@ func (suite *GlideTestSuite) TestZScan() { // Test NoScores option for Redis 8.0.0+ if suite.serverVersion >= "8.0.0" { - opts = options.NewZScanOptionsBuilder().SetNoScores(true) + opts = options.NewZScanOptions().SetNoScores(true) resCursor, resCollection, err = client.ZScanWithOptions(key1, initialCursor, opts) assert.NoError(suite.T(), err) cursor, err := strconv.ParseInt(resCursor, 10, 64) @@ -5614,13 +5635,13 @@ func (suite *GlideTestSuite) TestZScan() { assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) - opts = options.NewZScanOptionsBuilder().SetMatch("test").SetCount(1) + opts = options.NewZScanOptions().SetMatch("test").SetCount(1) _, _, err = client.ZScanWithOptions(stringKey, initialCursor, opts) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) // Negative count - opts = options.NewZScanOptionsBuilder().SetCount(-1) + opts = options.NewZScanOptions().SetCount(-1) _, _, err = client.ZScanWithOptions(key1, "-1", opts) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -5977,7 +5998,12 @@ func (suite *GlideTestSuite) TestXPendingFailures() { invalidConsumer := "invalid-consumer-" + uuid.New().String() suite.verifyOK( - client.XGroupCreateWithOptions(key, groupName, zeroStreamId, options.NewXGroupCreateOptions().SetMakeStream()), + client.XGroupCreateWithOptions( + key, + groupName, + zeroStreamId, + options.NewXGroupCreateOptions().SetMakeStream(), + ), ) command := []string{"XGroup", "CreateConsumer", key, groupName, consumer1} @@ -6241,7 +6267,7 @@ func (suite *GlideTestSuite) TestRestoreWithOptions() { deletedCount, err := client.Del([]string{key}) assert.Nil(t, err) assert.Equal(t, int64(1), deletedCount) - optsReplace := api.NewRestoreOptionsBuilder().SetReplace() + optsReplace := options.NewRestoreOptions().SetReplace() result_test1, err := client.RestoreWithOptions(key, int64(0), resultDump.Value(), optsReplace) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result_test1.Value()) @@ -6253,7 +6279,7 @@ func (suite *GlideTestSuite) TestRestoreWithOptions() { delete_test2, err := client.Del([]string{key}) assert.Nil(t, err) assert.Equal(t, int64(1), delete_test2) - opts_test2 := api.NewRestoreOptionsBuilder().SetABSTTL() + opts_test2 := options.NewRestoreOptions().SetABSTTL() result_test2, err := client.RestoreWithOptions(key, int64(0), resultDump.Value(), opts_test2) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result_test2.Value()) @@ -6265,7 +6291,7 @@ func (suite *GlideTestSuite) TestRestoreWithOptions() { delete_test3, err := client.Del([]string{key}) assert.Nil(t, err) assert.Equal(t, int64(1), delete_test3) - opts_test3 := api.NewRestoreOptionsBuilder().SetEviction(api.FREQ, 10) + opts_test3 := options.NewRestoreOptions().SetEviction(options.FREQ, 10) result_test3, err := client.RestoreWithOptions(key, int64(0), resultDump.Value(), opts_test3) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result_test3.Value()) @@ -6277,7 +6303,7 @@ func (suite *GlideTestSuite) TestRestoreWithOptions() { delete_test4, err := client.Del([]string{key}) assert.Nil(t, err) assert.Equal(t, int64(1), delete_test4) - opts_test4 := api.NewRestoreOptionsBuilder().SetEviction(api.IDLETIME, 10) + opts_test4 := options.NewRestoreOptions().SetEviction(options.IDLETIME, 10) result_test4, err := client.RestoreWithOptions(key, int64(0), resultDump.Value(), opts_test4) assert.Nil(suite.T(), err) assert.Equal(suite.T(), "OK", result_test4.Value()) @@ -7407,7 +7433,7 @@ func (suite *GlideTestSuite) TestCopyWithOptions() { suite.verifyOK(client.Set(key2, "World")) // Test 1: Check the copy command with options - optsCopy := api.NewCopyOptionsBuilder().SetReplace() + optsCopy := options.NewCopyOptions().SetReplace() resultCopy, err := client.CopyWithOptions(key, key2, optsCopy) assert.Nil(t, err) assert.True(t, resultCopy) @@ -7848,7 +7874,7 @@ func (suite *GlideTestSuite) TestZInter() { // intersection with scores zinterWithScoresResult, err := client.ZInterWithScores(options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), map[string]float64{"two": 5.5}, zinterWithScoresResult) @@ -7856,7 +7882,7 @@ func (suite *GlideTestSuite) TestZInter() { // intersect results with max aggregate zinterWithMaxAggregateResult, err := client.ZInterWithScores( options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateMax), + options.NewZInterOptions().SetAggregate(options.AggregateMax), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), map[string]float64{"two": 3.5}, zinterWithMaxAggregateResult) @@ -7864,7 +7890,7 @@ func (suite *GlideTestSuite) TestZInter() { // intersect results with min aggregate zinterWithMinAggregateResult, err := client.ZInterWithScores( options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateMin), + options.NewZInterOptions().SetAggregate(options.AggregateMin), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), map[string]float64{"two": 2.0}, zinterWithMinAggregateResult) @@ -7872,7 +7898,7 @@ func (suite *GlideTestSuite) TestZInter() { // intersect results with sum aggregate zinterWithSumAggregateResult, err := client.ZInterWithScores( options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), map[string]float64{"two": 5.5}, zinterWithSumAggregateResult) @@ -7885,7 +7911,7 @@ func (suite *GlideTestSuite) TestZInter() { {Key: key2, Weight: 2.0}, }, }, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), map[string]float64{"two": 11.0}, zinterWithWeightedKeysResult) @@ -7893,14 +7919,14 @@ func (suite *GlideTestSuite) TestZInter() { // non-existent key - empty intersection zinterWithNonExistentKeyResult, err := client.ZInterWithScores( options.KeyArray{Keys: []string{key1, key3}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NoError(suite.T(), err) assert.Empty(suite.T(), zinterWithNonExistentKeyResult) // empty key list - request error _, err = client.ZInterWithScores(options.KeyArray{Keys: []string{}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -7915,7 +7941,7 @@ func (suite *GlideTestSuite) TestZInter() { _, err = client.ZInterWithScores( options.KeyArray{Keys: []string{key1, key3}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NotNil(suite.T(), err) assert.IsType(suite.T(), &errors.RequestError{}, err) @@ -7960,7 +7986,7 @@ func (suite *GlideTestSuite) TestZInterStore() { // Store the intersection of key1 and key2 in key4 with max aggregate res, err = client.ZInterStoreWithOptions(key3, options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateMax), + options.NewZInterOptions().SetAggregate(options.AggregateMax), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), int64(2), res) @@ -7972,7 +7998,7 @@ func (suite *GlideTestSuite) TestZInterStore() { // Store the intersection of key1 and key2 in key5 with min aggregate res, err = client.ZInterStoreWithOptions(key3, options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateMin), + options.NewZInterOptions().SetAggregate(options.AggregateMin), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), int64(2), res) @@ -7984,7 +8010,7 @@ func (suite *GlideTestSuite) TestZInterStore() { // Store the intersection of key1 and key2 in key6 with sum aggregate res, err = client.ZInterStoreWithOptions(key3, options.KeyArray{Keys: []string{key1, key2}}, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateSum), + options.NewZInterOptions().SetAggregate(options.AggregateSum), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), int64(2), res) @@ -8017,7 +8043,7 @@ func (suite *GlideTestSuite) TestZInterStore() { {Key: key2, Weight: -2.0}, }, }, - options.NewZInterOptionsBuilder().SetAggregate(options.AggregateMin), + options.NewZInterOptions().SetAggregate(options.AggregateMin), ) assert.NoError(suite.T(), err) assert.Equal(suite.T(), int64(2), res) diff --git a/go/integTest/standalone_commands_test.go b/go/integTest/standalone_commands_test.go index 3bcec05e15..b36fe196b8 100644 --- a/go/integTest/standalone_commands_test.go +++ b/go/integTest/standalone_commands_test.go @@ -414,11 +414,11 @@ func (suite *GlideTestSuite) TestInfoStandalone() { } // info with option or with multiple options - sections := []api.Section{api.Cpu} + sections := []options.Section{options.Cpu} if suite.serverVersion >= "7.0.0" { - sections = append(sections, api.Memory) + sections = append(sections, options.Memory) } - info, err = client.InfoWithOptions(api.InfoOptions{Sections: sections}) + info, err = client.InfoWithOptions(options.InfoOptions{Sections: sections}) assert.NoError(t, err) for _, section := range sections { assert.Contains(t, strings.ToLower(info), strings.ToLower("# "+string(section)), "Section "+section+" is missing") diff --git a/go/integTest/vss_module_test.go b/go/integTest/vss_module_test.go index 39b720f210..10e10bd7ce 100644 --- a/go/integTest/vss_module_test.go +++ b/go/integTest/vss_module_test.go @@ -6,13 +6,16 @@ import ( "strings" "github.com/stretchr/testify/assert" - "github.com/valkey-io/valkey-glide/go/api" + "github.com/valkey-io/valkey-glide/go/api/options" ) func (suite *GlideTestSuite) TestModuleVerifyVssLoaded() { client := suite.defaultClusterClient() result, err := client.InfoWithOptions( - api.ClusterInfoOptions{InfoOptions: &api.InfoOptions{Sections: []api.Section{api.Server}}, Route: nil}, + options.ClusterInfoOptions{ + InfoOptions: &options.InfoOptions{Sections: []options.Section{options.Server}}, + RouteOption: nil, + }, ) assert.Nil(suite.T(), err)