-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: EdricCua <[email protected]>
- Loading branch information
Showing
14 changed files
with
505 additions
and
54 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
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
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,54 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
package options | ||
|
||
import ( | ||
"strconv" | ||
) | ||
|
||
// This base option struct represents the common set of optional arguments for the SCAN family of commands. | ||
// Concrete implementations of this class are tied to specific SCAN commands (`SCAN`, `SSCAN`, `HSCAN`). | ||
type BaseScanOptions struct { | ||
match string | ||
count int64 | ||
} | ||
|
||
func NewBaseScanOptionsBuilder() *BaseScanOptions { | ||
return &BaseScanOptions{} | ||
} | ||
|
||
/* | ||
The match filter is applied to the result of the command and will only include | ||
strings that match the pattern specified. If the sorted set is large enough for scan commands to return | ||
only a subset of the sorted set then there could be a case where the result is empty although there are | ||
items that match the pattern specified. This is due to the default `COUNT` being `10` which indicates | ||
that it will only fetch and match `10` items from the list. | ||
*/ | ||
func (scanOptions *BaseScanOptions) SetMatch(m string) *BaseScanOptions { | ||
scanOptions.match = m | ||
return scanOptions | ||
} | ||
|
||
/* | ||
`COUNT` is a just a hint for the command for how many elements to fetch from the | ||
sorted set. `COUNT` could be ignored until the sorted set is large enough for the `SCAN` commands to | ||
represent the results as compact single-allocation packed encoding. | ||
*/ | ||
func (scanOptions *BaseScanOptions) SetCount(c int64) *BaseScanOptions { | ||
scanOptions.count = c | ||
return scanOptions | ||
} | ||
|
||
func (opts *BaseScanOptions) ToArgs() ([]string, error) { | ||
args := []string{} | ||
var err error | ||
if opts.match != "" { | ||
args = append(args, MatchKeyword, opts.match) | ||
} | ||
|
||
if opts.count != 0 { | ||
args = append(args, CountKeyword, strconv.FormatInt(opts.count, 10)) | ||
} | ||
|
||
return args, err | ||
} |
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,9 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
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. | ||
) |
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,43 @@ | ||
// Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 | ||
|
||
package options | ||
|
||
// This struct represents the optional arguments for the HSCAN command. | ||
type HashScanOptions struct { | ||
BaseScanOptions | ||
noValue bool | ||
} | ||
|
||
func NewHashScanOptionsBuilder() *HashScanOptions { | ||
return &HashScanOptions{} | ||
} | ||
|
||
/* | ||
If this value is set to true, the HSCAN command will be called with NOVALUES option. | ||
In the NOVALUES option, values are not included in the response. | ||
*/ | ||
func (hashScanOptions *HashScanOptions) SetNoValue(noValue bool) *HashScanOptions { | ||
hashScanOptions.noValue = noValue | ||
return hashScanOptions | ||
} | ||
|
||
func (hashScanOptions *HashScanOptions) SetMatch(match string) *HashScanOptions { | ||
hashScanOptions.BaseScanOptions.SetMatch(match) | ||
return hashScanOptions | ||
} | ||
|
||
func (hashScanOptions *HashScanOptions) SetCount(count int64) *HashScanOptions { | ||
hashScanOptions.BaseScanOptions.SetCount(count) | ||
return hashScanOptions | ||
} | ||
|
||
func (options *HashScanOptions) ToArgs() ([]string, error) { | ||
args := []string{} | ||
baseArgs, err := options.BaseScanOptions.ToArgs() | ||
args = append(args, baseArgs...) | ||
|
||
if options.noValue { | ||
args = append(args, NoValue) | ||
} | ||
return args, err | ||
} |
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
Oops, something went wrong.