Skip to content

Commit ad8aaf6

Browse files
Go: fix options (#4181)
* Fix options. Signed-off-by: Yury-Fridlyand <[email protected]>
1 parent e309d0b commit ad8aaf6

28 files changed

+332
-406
lines changed

go/base_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8829,8 +8829,8 @@ func (client *baseClient) InvokeScriptWithOptions(
88298829
script options.Script,
88308830
scriptOptions options.ScriptOptions,
88318831
) (any, error) {
8832-
keys := scriptOptions.GetKeys()
8833-
args := scriptOptions.GetArgs()
8832+
keys := scriptOptions.Keys
8833+
args := scriptOptions.Args
88348834

88358835
response, err := client.executeScriptWithRoute(ctx, script.GetHash(), keys, args, nil)
88368836
if err != nil {

go/glide_cluster_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,7 +2396,7 @@ func (client *ClusterClient) InvokeScriptWithClusterOptions(
23962396
script options.Script,
23972397
clusterScriptOptions options.ClusterScriptOptions,
23982398
) (models.ClusterValue[any], error) {
2399-
args := clusterScriptOptions.GetArgs()
2399+
args := clusterScriptOptions.Args
24002400
route := clusterScriptOptions.Route
24012401

24022402
response, err := client.baseClient.executeScriptWithRoute(ctx, script.GetHash(), []string{}, args, route)
@@ -2519,7 +2519,7 @@ func (client *ClusterClient) ScriptFlushWithOptions(
25192519
}
25202520
return handleOkResponse(result)
25212521
}
2522-
result, err := client.executeCommandWithRoute(ctx, C.ScriptFlush, args, options.Route.Route)
2522+
result, err := client.executeCommandWithRoute(ctx, C.ScriptFlush, args, options.RouteOption.Route)
25232523
if err != nil {
25242524
return models.DefaultStringResponse, err
25252525
}

go/integTest/cluster_commands_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ func (suite *GlideTestSuite) TestLolwutWithOptions_WithAllNodes() {
11561156
options := options.ClusterLolwutOptions{
11571157
LolwutOptions: &options.LolwutOptions{
11581158
Version: 6,
1159-
Args: &[]int{10, 20},
1159+
Args: []int{10, 20},
11601160
},
11611161
RouteOption: &options.RouteOption{Route: config.AllNodes},
11621162
}

go/integTest/shared_commands_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4252,7 +4252,7 @@ func (suite *GlideTestSuite) TestSortWithOptions_DescendingOrder() {
42524252
options := options.NewSortOptions().
42534253
SetOrderBy(options.DESC).
42544254
SetIsAlpha(true).
4255-
SetSortLimit(0, 3)
4255+
SetLimit(options.Limit{Offset: 0, Count: 3})
42564256

42574257
sortResult, err := client.SortWithOptions(context.Background(), key, *options)
42584258

@@ -4359,7 +4359,7 @@ func (suite *GlideTestSuite) TestSortStoreWithOptions_Limit() {
43594359
sortedKey := "{listKey}" + uuid.New().String()
43604360
client.LPush(context.Background(), key, []string{"10", "20", "30", "40", "50"})
43614361

4362-
options := options.NewSortOptions().SetSortLimit(1, 3)
4362+
options := options.NewSortOptions().SetLimit(options.Limit{Offset: 1, Count: 3})
43634363
result, err := client.SortStoreWithOptions(context.Background(), key, sortedKey, *options)
43644364

43654365
suite.NoError(err)
@@ -4401,7 +4401,7 @@ func (suite *GlideTestSuite) TestSortReadyOnlyWithOptions_DescendingOrder() {
44014401
options := options.NewSortOptions().
44024402
SetOrderBy(options.DESC).
44034403
SetIsAlpha(true).
4404-
SetSortLimit(0, 3)
4404+
SetLimit(options.Limit{Offset: 0, Count: 3})
44054405

44064406
sortResult, err := client.SortReadOnlyWithOptions(context.Background(), key, *options)
44074407

@@ -9037,17 +9037,17 @@ func (suite *GlideTestSuite) TestXRangeAndXRevRange() {
90379037
*options.NewXRangeOptions().SetCount(0),
90389038
)
90399039
assert.NoError(suite.T(), err)
9040-
assert.Empty(suite.T(), xrangeResult)
9040+
assert.Nil(suite.T(), xrangeResult)
90419041

90429042
xrevrangeResult, err = client.XRevRangeWithOptions(
90439043
context.Background(),
90449044
key,
90459045
positiveInfinity,
90469046
negativeInfinity,
9047-
*options.NewXRangeOptions().SetCount(-1),
9047+
*options.NewXRangeOptions().SetCount(0),
90489048
)
90499049
assert.NoError(suite.T(), err)
9050-
assert.Empty(suite.T(), xrevrangeResult)
9050+
assert.Nil(suite.T(), xrevrangeResult)
90519051

90529052
// xrange and xrevrange against an empty stream
90539053
xdelResult, err := client.XDel(

go/options/base_scan_options.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
// This base option struct represents the common set of optional arguments for the SCAN family of commands.
1212
// Concrete implementations of this class are tied to specific SCAN commands (`SCAN`, `SSCAN`, `HSCAN`).
1313
type BaseScanOptions struct {
14-
match string
15-
count int64
14+
Match string
15+
Count int64
1616
}
1717

1818
func NewBaseScanOptions() *BaseScanOptions {
@@ -27,7 +27,7 @@ items that match the pattern specified. This is due to the default `COUNT` being
2727
that it will only fetch and match `10` items from the list.
2828
*/
2929
func (scanOptions *BaseScanOptions) SetMatch(m string) *BaseScanOptions {
30-
scanOptions.match = m
30+
scanOptions.Match = m
3131
return scanOptions
3232
}
3333

@@ -37,19 +37,19 @@ sorted set. `COUNT` could be ignored until the sorted set is large enough for th
3737
represent the results as compact single-allocation packed encoding.
3838
*/
3939
func (scanOptions *BaseScanOptions) SetCount(c int64) *BaseScanOptions {
40-
scanOptions.count = c
40+
scanOptions.Count = c
4141
return scanOptions
4242
}
4343

4444
func (opts *BaseScanOptions) ToArgs() ([]string, error) {
4545
args := []string{}
4646
var err error
47-
if opts.match != "" {
48-
args = append(args, constants.MatchKeyword, opts.match)
47+
if opts.Match != "" {
48+
args = append(args, constants.MatchKeyword, opts.Match)
4949
}
5050

51-
if opts.count != 0 {
52-
args = append(args, constants.CountKeyword, strconv.FormatInt(opts.count, 10))
51+
if opts.Count != 0 {
52+
args = append(args, constants.CountKeyword, strconv.FormatInt(opts.Count, 10))
5353
}
5454

5555
return args, err

go/options/bitcount_options.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ const (
1515

1616
// Optional arguments to `BitCount` in [BitMapCommands]
1717
type BitCountOptions struct {
18-
start *int64
19-
end *int64
20-
bitMapIndexType BitmapIndexType
18+
Start int64
19+
End int64
20+
BitMapIndexType BitmapIndexType
2121
}
2222

2323
func NewBitCountOptions() *BitCountOptions {
@@ -26,38 +26,29 @@ func NewBitCountOptions() *BitCountOptions {
2626

2727
// SetStart defines start byte to calculate bitcount in bitcount command.
2828
func (options *BitCountOptions) SetStart(start int64) *BitCountOptions {
29-
options.start = &start
29+
options.Start = start
3030
return options
3131
}
3232

3333
// SetEnd defines start byte to calculate bitcount in bitcount command.
3434
func (options *BitCountOptions) SetEnd(end int64) *BitCountOptions {
35-
options.end = &end
35+
options.End = end
3636
return options
3737
}
3838

3939
// SetBitmapIndexType to specify start and end are in BYTE or BIT
4040
func (options *BitCountOptions) SetBitmapIndexType(bitMapIndexType BitmapIndexType) *BitCountOptions {
41-
options.bitMapIndexType = bitMapIndexType
41+
options.BitMapIndexType = bitMapIndexType
4242
return options
4343
}
4444

4545
// ToArgs converts the options to a list of arguments.
4646
func (opts *BitCountOptions) ToArgs() ([]string, error) {
47-
args := []string{}
48-
var err error
49-
50-
if opts.start != nil {
51-
args = append(args, utils.IntToString(*opts.start))
52-
if opts.end != nil {
53-
args = append(args, utils.IntToString(*opts.end))
54-
if opts.bitMapIndexType != "" {
55-
if opts.bitMapIndexType == BIT || opts.bitMapIndexType == BYTE {
56-
args = append(args, string(opts.bitMapIndexType))
57-
}
58-
}
59-
}
47+
args := []string{utils.IntToString(opts.Start), utils.IntToString(opts.End)}
48+
49+
if opts.BitMapIndexType == BIT || opts.BitMapIndexType == BYTE {
50+
args = append(args, string(opts.BitMapIndexType))
6051
}
6152

62-
return args, err
53+
return args, nil
6354
}

go/options/bitpos_options.go

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88

99
// Optional arguments to `BitPos` in [BitMapCommands]
1010
type BitPosOptions struct {
11-
start *int64
12-
end *int64
13-
bitMapIndexType BitmapIndexType
11+
Start int64
12+
End int64
13+
BitMapIndexType BitmapIndexType
1414
}
1515

1616
func NewBitPosOptions() *BitPosOptions {
@@ -19,40 +19,28 @@ func NewBitPosOptions() *BitPosOptions {
1919

2020
// SetStart defines start byte to calculate bitpos in bitpos command.
2121
func (options *BitPosOptions) SetStart(start int64) *BitPosOptions {
22-
options.start = &start
22+
options.Start = start
2323
return options
2424
}
2525

2626
// SetEnd defines end byte to calculate bitpos in bitpos command.
2727
func (options *BitPosOptions) SetEnd(end int64) *BitPosOptions {
28-
options.end = &end
28+
options.End = end
2929
return options
3030
}
3131

3232
// SetBitmapIndexType to specify start and end are in BYTE or BIT
3333
func (options *BitPosOptions) SetBitmapIndexType(bitMapIndexType BitmapIndexType) *BitPosOptions {
34-
options.bitMapIndexType = bitMapIndexType
34+
options.BitMapIndexType = bitMapIndexType
3535
return options
3636
}
3737

3838
// ToArgs converts the options to a list of arguments.
3939
func (opts *BitPosOptions) ToArgs() ([]string, error) {
40-
args := []string{}
40+
args := []string{utils.IntToString(opts.Start), utils.IntToString(opts.End)}
4141

42-
if opts.start == nil {
43-
return args, nil
44-
}
45-
46-
args = append(args, utils.IntToString(*opts.start))
47-
48-
if opts.end == nil {
49-
return args, nil
50-
}
51-
52-
args = append(args, utils.IntToString(*opts.end))
53-
54-
if opts.bitMapIndexType == BIT || opts.bitMapIndexType == BYTE {
55-
args = append(args, string(opts.bitMapIndexType))
42+
if opts.BitMapIndexType == BIT || opts.BitMapIndexType == BYTE {
43+
args = append(args, string(opts.BitMapIndexType))
5644
}
5745

5846
return args, nil

go/options/cluster_scan_options.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// The options used for performing a Cluster scan.
1010
type ClusterScanOptions struct {
1111
BaseScanOptions
12-
scanType constants.ObjectType
12+
ScanType constants.ObjectType
1313
}
1414

1515
// Creates a options struct to be used in the Cluster Scan.
@@ -19,19 +19,19 @@ func NewClusterScanOptions() *ClusterScanOptions {
1919

2020
// SetMatch sets the match pattern for Cluster Scan command.
2121
func (scanOptions *ClusterScanOptions) SetMatch(m string) *ClusterScanOptions {
22-
scanOptions.BaseScanOptions.match = m
22+
scanOptions.BaseScanOptions.Match = m
2323
return scanOptions
2424
}
2525

2626
// SetCount sets the count for the Cluster Scan command.
2727
func (scanOptions *ClusterScanOptions) SetCount(c int64) *ClusterScanOptions {
28-
scanOptions.BaseScanOptions.count = c
28+
scanOptions.BaseScanOptions.Count = c
2929
return scanOptions
3030
}
3131

3232
// SetType sets the type to look for during the Cluster Scan.
3333
func (scanOptions *ClusterScanOptions) SetType(t constants.ObjectType) *ClusterScanOptions {
34-
scanOptions.scanType = t
34+
scanOptions.ScanType = t
3535
return scanOptions
3636
}
3737

@@ -40,8 +40,8 @@ func (opts *ClusterScanOptions) ToArgs() ([]string, error) {
4040
baseArgs, err := opts.BaseScanOptions.ToArgs()
4141
args = append(args, baseArgs...)
4242

43-
if string(opts.scanType) != "" {
44-
args = append(args, constants.TypeKeyword, string(opts.scanType))
43+
if string(opts.ScanType) != "" {
44+
args = append(args, constants.TypeKeyword, string(opts.ScanType))
4545
}
4646

4747
return args, err

0 commit comments

Comments
 (0)