-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Go: Implement GetBit, SetBit, BitCount and Wait commands (#2918)
* Added bitmap commands,wait commands Signed-off-by: Niharika Bhavaraju <[email protected]>
- Loading branch information
1 parent
490c3d4
commit 918162b
Showing
5 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.