Skip to content

Commit

Permalink
Fix merge conflict
Browse files Browse the repository at this point in the history
Signed-off-by: EdricCua <[email protected]>
  • Loading branch information
EdricCua committed Jan 21, 2025
2 parents 9b9de5e + 918162b commit c35ce05
Show file tree
Hide file tree
Showing 16 changed files with 1,137 additions and 315 deletions.
416 changes: 394 additions & 22 deletions go/api/base_client.go

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions go/api/bitmap_commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

package api

import "github.com/valkey-io/valkey-glide/go/glide/api/options"

// Supports commands and transactions for the "Bitmap" group of commands for standalone and cluster clients.
//
// See [valkey.io] for details.
//
// [valkey.io]: https://valkey.io/commands/#bitmap
type BitmapCommands interface {
SetBit(key string, offset int64, value int64) (int64, error)

GetBit(key string, offset int64) (int64, error)

BitCount(key string) (int64, error)

BitCountWithOptions(key string, options *options.BitCountOptions) (int64, error)
}
2 changes: 2 additions & 0 deletions go/api/generic_base_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ type GenericBaseCommands interface {
// [valkey.io]: https://valkey.io/commands/sort/
SortReadOnlyWithOptions(key string, sortOptions *options.SortOptions) ([]Result[string], error)

Wait(numberOfReplicas int64, timeout int64) (int64, error)

Copy(source string, destination string) (bool, error)

CopyWithOptions(source string, destination string, option *CopyOptions) (bool, error)
Expand Down
2 changes: 1 addition & 1 deletion go/api/glide_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (client *glideClient) ConfigSet(parameters map[string]string) (string, erro
return handleStringResponse(result)
}

func (client *glideClient) ConfigGet(args []string) (map[Result[string]]Result[string], error) {
func (client *glideClient) ConfigGet(args []string) (map[string]string, error) {
res, err := client.executeCommand(C.ConfigGet, args)
if err != nil {
return nil, err
Expand Down
14 changes: 8 additions & 6 deletions go/api/hash_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,10 @@ type HashCommands interface {
//
// For example:
// fieldValueMap, err := client.HGetAll("my_hash")
// // field1 equals api.CreateStringResult("field1")
// // value1 equals api.CreateStringResult("value1")
// // field2 equals api.CreateStringResult("field2")
// // value2 equals api.CreateStringResult("value2")
// // fieldValueMap equals map[api.Result[string]]api.Result[string]{field1: value1, field2: value2}
// // fieldValueMap equals map[string]string{field1: value1, field2: value2}
//
// [valkey.io]: https://valkey.io/commands/hgetall/
HGetAll(key string) (map[Result[string]]Result[string], error)
HGetAll(key string) (map[string]string, error)

// HMGet returns the values associated with the specified fields in the hash stored at key.
//
Expand Down Expand Up @@ -287,5 +283,11 @@ type HashCommands interface {

HScan(key string, cursor string) (string, []string, error)

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

HRandFieldWithCount(key string, count int64) ([]string, error)

HRandFieldWithCountWithValues(key string, count int64) ([][]string, error)

HScanWithOptions(key string, cursor string, options *options.HashScanOptions) (string, []string, error)
}
16 changes: 8 additions & 8 deletions go/api/list_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ type ListCommands interface {
// For example:
// result, err := client.LPush("my_list", []string{"one", "two", "three"})
// result, err := client.LMPop([]string{"my_list"}, api.Left)
// result[api.CreateStringResult("my_list")] = []api.Result[string]{api.CreateStringResult("three")}
// result["my_list"] = []string{"three"}
//
// [valkey.io]: https://valkey.io/commands/lmpop/
LMPop(keys []string, listDirection ListDirection) (map[Result[string]][]Result[string], error)
LMPop(keys []string, listDirection ListDirection) (map[string][]string, error)

// Pops one or more elements from the first non-empty list from the provided keys.
//
Expand All @@ -514,10 +514,10 @@ type ListCommands interface {
// For example:
// result, err := client.LPush("my_list", []string{"one", "two", "three"})
// result, err := client.LMPopCount([]string{"my_list"}, api.Left, int64(1))
// result[api.CreateStringResult("my_list")] = []api.Result[string]{api.CreateStringResult("three")}
// result["my_list"] = []string{"three"}
//
// [valkey.io]: https://valkey.io/commands/lmpop/
LMPopCount(keys []string, listDirection ListDirection, count int64) (map[Result[string]][]Result[string], error)
LMPopCount(keys []string, listDirection ListDirection, count int64) (map[string][]string, error)

// Blocks the connection until it pops one element from the first non-empty list from the provided keys. BLMPop is the
// blocking variant of [api.LMPop].
Expand All @@ -544,11 +544,11 @@ type ListCommands interface {
// For example:
// result, err := client.LPush("my_list", []string{"one", "two", "three"})
// result, err := client.BLMPop([]string{"my_list"}, api.Left, float64(0.1))
// result[api.CreateStringResult("my_list")] = []api.Result[string]{api.CreateStringResult("three")}
// result["my_list"] = []string{"three"}
//
// [valkey.io]: https://valkey.io/commands/blmpop/
// [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands
BLMPop(keys []string, listDirection ListDirection, timeoutSecs float64) (map[Result[string]][]Result[string], error)
BLMPop(keys []string, listDirection ListDirection, timeoutSecs float64) (map[string][]string, error)

// Blocks the connection until it pops one or more elements from the first non-empty list from the provided keys.
// BLMPopCount is the blocking variant of [api.LMPopCount].
Expand Down Expand Up @@ -576,7 +576,7 @@ type ListCommands interface {
// For example:
// result, err: client.LPush("my_list", []string{"one", "two", "three"})
// result, err := client.BLMPopCount([]string{"my_list"}, api.Left, int64(1), float64(0.1))
// result[api.CreateStringResult("my_list")] = []api.Result[string]{api.CreateStringResult("three")}
// result["my_list"] = []string{"three"}
//
// [valkey.io]: https://valkey.io/commands/blmpop/
// [Blocking Commands]: https://github.com/valkey-io/valkey-glide/wiki/General-Concepts#blocking-commands
Expand All @@ -585,7 +585,7 @@ type ListCommands interface {
listDirection ListDirection,
count int64,
timeoutSecs float64,
) (map[Result[string]][]Result[string], error)
) (map[string][]string, error)

// Sets the list element at index to element.
// The index is zero-based, so 0 means the first element,1 the second element and so on. Negative indices can be used to
Expand Down
63 changes: 63 additions & 0 deletions go/api/options/bitcount_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0

package options

import (
"github.com/valkey-io/valkey-glide/go/glide/utils"
)

type BitmapIndexType string

const (
BYTE BitmapIndexType = "BYTE"
BIT BitmapIndexType = "BIT"
)

// Optional arguments to `BitCount` in [BitMapCommands]
type BitCountOptions struct {
start *int64
end *int64
bitMapIndexType BitmapIndexType
}

func NewBitCountOptionsBuilder() *BitCountOptions {
return &BitCountOptions{}
}

// SetStart defines start byte to calculate bitcount in bitcount command.
func (options *BitCountOptions) SetStart(start int64) *BitCountOptions {
options.start = &start
return options
}

// SetEnd defines start byte to calculate bitcount in bitcount command.
func (options *BitCountOptions) SetEnd(end int64) *BitCountOptions {
options.end = &end
return options
}

// SetBitmapIndexType to specify start and end are in BYTE or BIT
func (options *BitCountOptions) SetBitmapIndexType(bitMapIndexType BitmapIndexType) *BitCountOptions {
options.bitMapIndexType = bitMapIndexType
return options
}

// ToArgs converts the options to a list of arguments.
func (opts *BitCountOptions) ToArgs() ([]string, error) {
args := []string{}
var err error

if opts.start != nil {
args = append(args, utils.IntToString(*opts.start))
if opts.end != nil {
args = append(args, utils.IntToString(*opts.end))
if opts.bitMapIndexType != "" {
if opts.bitMapIndexType == BIT || opts.bitMapIndexType == BYTE {
args = append(args, string(opts.bitMapIndexType))
}
}
}
}

return args, err
}
11 changes: 6 additions & 5 deletions go/api/options/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
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.
NoScores string = "NOSCORES" // Valkey API keyword for the no scores option for zscan command.
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.
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`.
)
32 changes: 28 additions & 4 deletions go/api/options/stream_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ func (xpo *XPendingOptions) SetConsumer(consumer string) *XPendingOptions {
func (xpo *XPendingOptions) ToArgs() ([]string, error) {
args := []string{}

// if minIdleTime is set, we need to add an `IDLE` argument along with the minIdleTime
if xpo.minIdleTime > 0 {
args = append(args, "IDLE")
args = append(args, utils.IntToString(xpo.minIdleTime))
Expand Down Expand Up @@ -280,9 +279,6 @@ func (xgco *XGroupCreateOptions) SetMakeStream() *XGroupCreateOptions {
return xgco
}

// A value representing the number of stream entries already read by the group.
//
// Since Valkey version 7.0.0.
func (xgco *XGroupCreateOptions) SetEntriesRead(entriesRead int64) *XGroupCreateOptions {
xgco.entriesRead = entriesRead
return xgco
Expand All @@ -302,3 +298,31 @@ func (xgco *XGroupCreateOptions) ToArgs() ([]string, error) {

return args, nil
}

// Optional arguments for `XGroupSetId` in [StreamCommands]
type XGroupSetIdOptions struct {
entriesRead int64
}

// Create new empty `XGroupSetIdOptions`
func NewXGroupSetIdOptionsOptions() *XGroupSetIdOptions {
return &XGroupSetIdOptions{-1}
}

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

func (xgsio *XGroupSetIdOptions) ToArgs() ([]string, error) {
var args []string

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

return args, nil
}
Loading

0 comments on commit c35ce05

Please sign in to comment.