Skip to content

Commit a415f72

Browse files
Fix return types.
Signed-off-by: Yury-Fridlyand <yury.fridlyand@improving.com>
1 parent dbb83b6 commit a415f72

File tree

7 files changed

+169
-349
lines changed

7 files changed

+169
-349
lines changed

go/api/base_client.go

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func (client *baseClient) MGet(keys []string) ([]Result[string], error) {
258258
return nil, err
259259
}
260260

261-
return handleStringArrayResponse(result)
261+
return handleStringOrNilArrayResponse(result)
262262
}
263263

264264
func (client *baseClient) Incr(key string) (int64, error) {
@@ -391,7 +391,7 @@ func (client *baseClient) HMGet(key string, fields []string) ([]Result[string],
391391
return nil, err
392392
}
393393

394-
return handleStringArrayResponse(result)
394+
return handleStringOrNilArrayResponse(result)
395395
}
396396

397397
func (client *baseClient) HSet(key string, values map[string]string) (int64, error) {
@@ -430,7 +430,7 @@ func (client *baseClient) HLen(key string) (int64, error) {
430430
return handleIntResponse(result)
431431
}
432432

433-
func (client *baseClient) HVals(key string) ([]Result[string], error) {
433+
func (client *baseClient) HVals(key string) ([]string, error) {
434434
result, err := client.executeCommand(C.HVals, []string{key})
435435
if err != nil {
436436
return nil, err
@@ -448,7 +448,7 @@ func (client *baseClient) HExists(key string, field string) (bool, error) {
448448
return handleBoolResponse(result)
449449
}
450450

451-
func (client *baseClient) HKeys(key string) ([]Result[string], error) {
451+
func (client *baseClient) HKeys(key string) ([]string, error) {
452452
result, err := client.executeCommand(C.HKeys, []string{key})
453453
if err != nil {
454454
return nil, err
@@ -527,13 +527,13 @@ func (client *baseClient) LPop(key string) (Result[string], error) {
527527
return handleStringOrNilResponse(result)
528528
}
529529

530-
func (client *baseClient) LPopCount(key string, count int64) ([]Result[string], error) {
530+
func (client *baseClient) LPopCount(key string, count int64) ([]string, error) {
531531
result, err := client.executeCommand(C.LPop, []string{key, utils.IntToString(count)})
532532
if err != nil {
533533
return nil, err
534534
}
535535

536-
return handleStringArrayOrNullResponse(result)
536+
return handleStringArrayOrNilResponse(result)
537537
}
538538

539539
func (client *baseClient) LPos(key string, element string) (Result[int64], error) {
@@ -554,7 +554,7 @@ func (client *baseClient) LPosWithOptions(key string, element string, options *L
554554
return handleIntOrNilResponse(result)
555555
}
556556

557-
func (client *baseClient) LPosCount(key string, element string, count int64) ([]Result[int64], error) {
557+
func (client *baseClient) LPosCount(key string, element string, count int64) ([]int64, error) {
558558
result, err := client.executeCommand(C.LPos, []string{key, element, CountKeyword, utils.IntToString(count)})
559559
if err != nil {
560560
return nil, err
@@ -568,7 +568,7 @@ func (client *baseClient) LPosCountWithOptions(
568568
element string,
569569
count int64,
570570
options *LPosOptions,
571-
) ([]Result[int64], error) {
571+
) ([]int64, error) {
572572
result, err := client.executeCommand(
573573
C.LPos,
574574
append([]string{key, element, CountKeyword, utils.IntToString(count)}, options.toArgs()...),
@@ -768,7 +768,7 @@ func (client *baseClient) SMove(source string, destination string, member string
768768
return handleBoolResponse(result)
769769
}
770770

771-
func (client *baseClient) LRange(key string, start int64, end int64) ([]Result[string], error) {
771+
func (client *baseClient) LRange(key string, start int64, end int64) ([]string, error) {
772772
result, err := client.executeCommand(C.LRange, []string{key, utils.IntToString(start), utils.IntToString(end)})
773773
if err != nil {
774774
return nil, err
@@ -822,13 +822,13 @@ func (client *baseClient) RPop(key string) (Result[string], error) {
822822
return handleStringOrNilResponse(result)
823823
}
824824

825-
func (client *baseClient) RPopCount(key string, count int64) ([]Result[string], error) {
825+
func (client *baseClient) RPopCount(key string, count int64) ([]string, error) {
826826
result, err := client.executeCommand(C.RPop, []string{key, utils.IntToString(count)})
827827
if err != nil {
828828
return nil, err
829829
}
830830

831-
return handleStringArrayOrNullResponse(result)
831+
return handleStringArrayOrNilResponse(result)
832832
}
833833

834834
func (client *baseClient) LInsert(
@@ -853,22 +853,22 @@ func (client *baseClient) LInsert(
853853
return handleIntResponse(result)
854854
}
855855

856-
func (client *baseClient) BLPop(keys []string, timeoutSecs float64) ([]Result[string], error) {
856+
func (client *baseClient) BLPop(keys []string, timeoutSecs float64) ([]string, error) {
857857
result, err := client.executeCommand(C.BLPop, append(keys, utils.FloatToString(timeoutSecs)))
858858
if err != nil {
859859
return nil, err
860860
}
861861

862-
return handleStringArrayOrNullResponse(result)
862+
return handleStringArrayOrNilResponse(result)
863863
}
864864

865-
func (client *baseClient) BRPop(keys []string, timeoutSecs float64) ([]Result[string], error) {
865+
func (client *baseClient) BRPop(keys []string, timeoutSecs float64) ([]string, error) {
866866
result, err := client.executeCommand(C.BRPop, append(keys, utils.FloatToString(timeoutSecs)))
867867
if err != nil {
868868
return nil, err
869869
}
870870

871-
return handleStringArrayOrNullResponse(result)
871+
return handleStringArrayOrNilResponse(result)
872872
}
873873

874874
func (client *baseClient) RPushX(key string, elements []string) (int64, error) {
@@ -1258,12 +1258,12 @@ func (client *baseClient) Unlink(keys []string) (int64, error) {
12581258
return handleIntResponse(result)
12591259
}
12601260

1261-
func (client *baseClient) Type(key string) (Result[string], error) {
1261+
func (client *baseClient) Type(key string) (string, error) {
12621262
result, err := client.executeCommand(C.Type, []string{key})
12631263
if err != nil {
1264-
return CreateNilStringResult(), err
1264+
return defaultStringResponse, err
12651265
}
1266-
return handleStringOrNilResponse(result)
1266+
return handleStringResponse(result)
12671267
}
12681268

12691269
func (client *baseClient) Touch(keys []string) (int64, error) {
@@ -1275,12 +1275,12 @@ func (client *baseClient) Touch(keys []string) (int64, error) {
12751275
return handleIntResponse(result)
12761276
}
12771277

1278-
func (client *baseClient) Rename(key string, newKey string) (Result[string], error) {
1278+
func (client *baseClient) Rename(key string, newKey string) (string, error) {
12791279
result, err := client.executeCommand(C.Rename, []string{key, newKey})
12801280
if err != nil {
1281-
return CreateNilStringResult(), err
1281+
return defaultStringResponse, err
12821282
}
1283-
return handleStringOrNilResponse(result)
1283+
return handleStringResponse(result)
12841284
}
12851285

12861286
func (client *baseClient) Renamenx(key string, newKey string) (bool, error) {
@@ -1575,20 +1575,19 @@ func (client *baseClient) BZPopMin(keys []string, timeoutSecs float64) (Result[K
15751575
//
15761576
// Example:
15771577
//
1578-
// // Retrieve all members of a sorted set in ascending order
1579-
// result, err := client.ZRange("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
1580-
//
1581-
// // Retrieve members within a score range in descending order
1578+
// // Retrieve all members of a sorted set in ascending order
1579+
// result, err := client.ZRange("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
15821580
//
1583-
// query := options.NewRangeByScoreQuery(options.NewScoreBoundary(3, false),
1584-
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
1585-
//
1586-
// .SetReverse()
1587-
// result, err := client.ZRange("my_sorted_set", query)
1588-
// // `result` contains members which have scores within the range of negative infinity to 3, in descending order
1581+
// // Retrieve members within a score range in descending order
1582+
// query := options.NewRangeByScoreQuery(
1583+
// options.NewScoreBoundary(3, false),
1584+
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
1585+
// SetReverse()
1586+
// result, err := client.ZRange("my_sorted_set", query)
1587+
// // `result` contains members which have scores within the range of negative infinity to 3, in descending order
15891588
//
15901589
// [valkey.io]: https://valkey.io/commands/zrange/
1591-
func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]Result[string], error) {
1590+
func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]string, error) {
15921591
args := make([]string, 0, 10)
15931592
args = append(args, key)
15941593
args = append(args, rangeQuery.ToArgs()...)
@@ -1619,17 +1618,16 @@ func (client *baseClient) ZRange(key string, rangeQuery options.ZRangeQuery) ([]
16191618
//
16201619
// Example:
16211620
//
1622-
// // Retrieve all members of a sorted set in ascending order
1623-
// result, err := client.ZRangeWithScores("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
1624-
//
1625-
// // Retrieve members within a score range in descending order
1626-
//
1627-
// query := options.NewRangeByScoreQuery(options.NewScoreBoundary(3, false),
1628-
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
1621+
// // Retrieve all members of a sorted set in ascending order
1622+
// result, err := client.ZRangeWithScores("my_sorted_set", options.NewRangeByIndexQuery(0, -1))
16291623
//
1630-
// SetReverse()
1631-
// result, err := client.ZRangeWithScores("my_sorted_set", query)
1632-
// // `result` contains members with scores within the range of negative infinity to 3, in descending order
1624+
// // Retrieve members within a score range in descending order
1625+
// query := options.NewRangeByScoreQuery(
1626+
// options.NewScoreBoundary(3, false),
1627+
// options.NewInfiniteScoreBoundary(options.NegativeInfinity)).
1628+
// SetReverse()
1629+
// result, err := client.ZRangeWithScores("my_sorted_set", query)
1630+
// // `result` contains members with scores within the range of negative infinity to 3, in descending order
16331631
//
16341632
// [valkey.io]: https://valkey.io/commands/zrange/
16351633
func (client *baseClient) ZRangeWithScores(

go/api/generic_base_commands.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,17 +367,17 @@ type GenericBaseCommands interface {
367367
// key - string
368368
//
369369
// Return value:
370-
// If the key exists, the type of the stored value is returned. Otherwise, a none" string is returned.
370+
// If the key exists, the type of the stored value is returned. Otherwise, a "none" string is returned.
371371
//
372372
// Example:
373373
// result, err := client.Type([]string{"key"})
374374
// if err != nil {
375375
// // handle error
376376
// }
377-
// fmt.Println(result.Value()) // Output: string
377+
// fmt.Println(result) // Output: string
378378
//
379379
// [valkey.io]: Https://valkey.io/commands/type/
380-
Type(key string) (Result[string], error)
380+
Type(key string) (string, error)
381381

382382
// Renames key to new key.
383383
// If new Key already exists it is overwritten.
@@ -397,10 +397,10 @@ type GenericBaseCommands interface {
397397
// if err != nil {
398398
// // handle error
399399
// }
400-
// fmt.Println(result.Value()) // Output: OK
400+
// fmt.Println(result) // Output: OK
401401
//
402402
// [valkey.io]: https://valkey.io/commands/rename/
403-
Rename(key string, newKey string) (Result[string], error)
403+
Rename(key string, newKey string) (string, error)
404404

405405
// Renames key to newkey if newKey does not yet exist.
406406
//

go/api/hash_commands.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,14 @@ type HashCommands interface {
172172
// key - The key of the hash.
173173
//
174174
// Return value:
175-
// A slice of Result[string]s containing all the values in the hash, or an empty slice when key does not exist.
175+
// A slice containing all the values in the hash, or an empty slice when key does not exist.
176176
//
177177
// For example:
178178
// values, err := client.HVals("myHash")
179-
// // value1 equals api.CreateStringResult("value1")
180-
// // value2 equals api.CreateStringResult("value2")
181-
// // value3 equals api.CreateStringResult("value3")
182-
// // values equals []api.Result[string]{value1, value2, value3}
179+
// values: []string{"value1", "value2", "value3"}
183180
//
184181
// [valkey.io]: https://valkey.io/commands/hvals/
185-
HVals(key string) ([]Result[string], error)
182+
HVals(key string) ([]string, error)
186183

187184
// HExists returns if field is an existing field in the hash stored at key.
188185
//
@@ -215,16 +212,14 @@ type HashCommands interface {
215212
// key - The key of the hash.
216213
//
217214
// Return value:
218-
// A slice of Result[string]s containing all the field names in the hash, or an empty slice when key does not exist.
215+
// A slice containing all the field names in the hash, or an empty slice when key does not exist.
219216
//
220217
// For example:
221218
// names, err := client.HKeys("my_hash")
222-
// // field1 equals api.CreateStringResult("field_1")
223-
// // field2 equals api.CreateStringResult("field_2")
224-
// // names equals []api.Result[string]{field1, field2}
219+
// names: []string{"field1", "field2"}
225220
//
226221
// [valkey.io]: https://valkey.io/commands/hkeys/
227-
HKeys(key string) ([]Result[string], error)
222+
HKeys(key string) ([]string, error)
228223

229224
// HStrLen returns the string length of the value associated with field in the hash stored at key.
230225
// If the key or the field do not exist, 0 is returned.

0 commit comments

Comments
 (0)