Skip to content

Commit

Permalink
Merge branch 'main' into Feature-dummyScan
Browse files Browse the repository at this point in the history
Signed-off-by: avifenesh <[email protected]>
  • Loading branch information
avifenesh committed Dec 22, 2024
2 parents c3ee29d + ef18be3 commit f72a04b
Show file tree
Hide file tree
Showing 26 changed files with 1,486 additions and 91 deletions.
51 changes: 35 additions & 16 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,11 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
engine-version: ${{ matrix.engine.version }}

- name: Install tools for Go ${{ matrix.go }}
working-directory: ./go
run: make install-tools-go${{ matrix.go }}

- name: Set LD_LIBRARY_PATH
if: ${{ matrix.os == 'ubuntu-latest' }}
run: echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/go/target/release/deps/" >> $GITHUB_ENV

- name: Build client
working-directory: ./go
run: make build

- name: Run tests
working-directory: ./go
run: make test
- name: Install & build & test
working-directory: go
run: |
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/go/target/release/deps/
make install-tools-go${{ matrix.go }} build unit-test integ-test
- uses: ./.github/workflows/test-benchmark
with:
Expand Down Expand Up @@ -216,7 +206,7 @@ jobs:
working-directory: go
run: |
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/go/target/release/deps/
make install-tools-go${{ matrix.go }} build test
make install-tools-go${{ matrix.go }} build unit-test integ-test
- name: Upload test reports
if: always()
Expand All @@ -227,3 +217,32 @@ jobs:
path: |
utils/clusters/**
benchmarks/results/**
test-modules:
if: (github.repository_owner == 'valkey-io' && github.event_name == 'workflow_dispatch') || github.event.pull_request.head.repo.owner.login == 'valkey-io'
environment: AWS_ACTIONS
name: Modules Tests
runs-on: [self-hosted, linux, ARM64]
timeout-minutes: 15
steps:
- name: Setup self-hosted runner access
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/valkey-glide

- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20.0"
cache-dependency-path: go/go.sum

- name: Build and test
working-directory: ./go
run: |
make install-tools-go1.20.0
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/go/target/release/deps/
make build
make modules-test cluster-endpoints=${{ secrets.MEMDB_MODULES_ENDPOINT }} tls=true
# TODO:
# Upload test reports
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
#### Changes

* Go: Add SUNIONSTORE command ([#2805](https://github.com/valkey-io/valkey-glide/pull/2805)
* Go: Add SUNION ([#2787](https://github.com/valkey-io/valkey-glide/pull/2787)
* Go: Add HINCRBY command ([#2847](https://github.com/valkey-io/valkey-glide/pull/2847))
* Go: Add HINCRBYFLOAT command ([#2846](https://github.com/valkey-io/valkey-glide/pull/2846))
* Go: Add SUNIONSTORE command ([#2805](https://github.com/valkey-io/valkey-glide/pull/2805))
* Go: Add SUNION ([#2787](https://github.com/valkey-io/valkey-glide/pull/2787))
* Java: bump `netty` version ([#2795](https://github.com/valkey-io/valkey-glide/pull/2795))
* Java: Bump protobuf (protoc) version ([#2796](https://github.com/valkey-io/valkey-glide/pull/2796), [#2800](https://github.com/valkey-io/valkey-glide/pull/2800))
* Go: Add `SInterStore` ([#2779](https://github.com/valkey-io/valkey-glide/issues/2779))
* Node: Remove native package references for MacOs x64 architecture ([#2799](https://github.com/valkey-io/valkey-glide/issues/2799))
* Go: Add `ZIncrBy` command ([#2830](https://github.com/valkey-io/valkey-glide/pull/2830))
* Go: Add `SScan` and `SMove` ([#2789](https://github.com/valkey-io/valkey-glide/issues/2789))
* Go: Add `ZADD` ([#2813](https://github.com/valkey-io/valkey-glide/issues/2813))

#### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion go/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ authors = ["Valkey GLIDE Maintainers"]
crate-type = ["cdylib"]

[dependencies]
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "tls", "tokio-native-tls-comp", "tls-rustls-insecure"] }
redis = { path = "../glide-core/redis-rs/redis", features = ["aio", "tokio-comp", "connection-manager", "tokio-rustls-comp"] }
glide-core = { path = "../glide-core", features = ["socket-layer"] }
tokio = { version = "^1", features = ["rt", "macros", "rt-multi-thread", "time"] }
protobuf = { version = "3.3.0", features = [] }
Expand Down
23 changes: 14 additions & 9 deletions go/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,30 +140,35 @@ Before starting this step, make sure you've installed all software requirements.

### Test

To run tests, use the following command:
To run tests, use the benefit on makefile. To run unit tests, run the following command:

```bash
go test -race ./...
make unit-test
```

For more detailed test output, add the `-v` flag:
To run integration tests, run:

```bash
go test -race ./... -v
make integ-test
```

To execute a specific test, include `-run <test_name>`. For example:
To run modules tests, run:

```bash
go test -race ./... -run TestConnectionRequestProtobufGeneration_allFieldsSet -v
make modules-test
```

### Submodules
To execute a specific test, include `test-filter=<test_name>`. For example:

After pulling new changes, ensure that you update the submodules by running the following command:
```bash
make unit-test test-filter=TestConnectionRequestProtobufGeneration_allFieldsSet
```

Integration and modules tests accept `standalone-endpoints`, `cluster-endpoints` and `tls` parameters to run tests on existing servers.
By default, those test suite start standalone and cluster servers without TLS and stop them at the end.

```bash
git submodule update --init --recursive
make integ-test standalone-endpoints=localhost:6379 cluster-endpoints=localhost:7000 tls=true
```

### Generate protobuf files
Expand Down
26 changes: 23 additions & 3 deletions go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ clean:
go clean
rm -f lib.h
rm -f benchmarks/benchmarks

rm -rf protobuf
rm -rf target

build-glide-client:
cargo build --release
Expand All @@ -49,6 +50,7 @@ build-glide-client-debug:
cbindgen --config cbindgen.toml --crate glide-rs --output lib.h

generate-protobuf:
rm -rf protobuf
mkdir -p protobuf
protoc --proto_path=../glide-core/src/protobuf \
--go_opt=Mconnection_request.proto=github.com/valkey-io/valkey-glide/go/protobuf \
Expand All @@ -72,13 +74,31 @@ format:
gofumpt -w .
golines -w --shorten-comments -m 127 .

test:
# unit tests - skip complete IT suite (including MT)
unit-test:
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.so|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
go test -v -race ./... -skip TestGlideTestSuite $(if $(test-filter), -run $(test-filter))

# integration tests - run subtask with skipping modules tests
integ-test: export TEST_FILTER = -skip TestGlideTestSuite/TestModule $(if $(test-filter), -run $(test-filter))
integ-test: __it

# modules tests - run substask with default filter
modules-test: export TEST_FILTER = $(if $(test-filter), -run $(test-filter), -run TestGlideTestSuite/TestModule)
modules-test: __it

__it:
LD_LIBRARY_PATH=$(shell find . -name libglide_rs.so|grep -w release|tail -1|xargs dirname|xargs readlink -f):${LD_LIBRARY_PATH} \
go test -v -race ./...
go test -v -race ./integTest/... \
$(TEST_FILTER) \
$(if $(filter true, $(tls)), --tls,) \
$(if $(standalone-endpoints), --standalone-endpoints=$(standalone-endpoints)) \
$(if $(cluster-endpoints), --cluster-endpoints=$(cluster-endpoints))

# Note: this task is no longer run by CI because:
# - build failures that occur while running the task can be hidden by the task; CI still reports success in these scenarios.
# - there is not a good way to both generate a test report and log the test outcomes to GH actions.
# TODO: fix this and include -run/-skip flags
test-and-report:
mkdir -p reports
go test -v -race ./... -json | go-test-report -o reports/test-report.html
149 changes: 147 additions & 2 deletions go/api/base_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strconv"
"unsafe"

"github.com/valkey-io/valkey-glide/go/glide/api/options"
"github.com/valkey-io/valkey-glide/go/glide/protobuf"
"github.com/valkey-io/valkey-glide/go/glide/utils"
"google.golang.org/protobuf/proto"
Expand All @@ -26,6 +27,7 @@ type BaseClient interface {
HashCommands
ListCommands
SetCommands
SortedSetCommands
ConnectionManagementCommands
GenericBaseCommands
// Close terminates the client by closing all associated resources.
Expand Down Expand Up @@ -102,7 +104,10 @@ func (client *baseClient) Close() {
client.coreClient = nil
}

func (client *baseClient) executeCommand(requestType C.RequestType, args []string) (*C.struct_CommandResponse, error) {
func (client *baseClient) executeCommand(
requestType C.RequestType,
args []string,
) (*C.struct_CommandResponse, error) {
if client.coreClient == nil {
return nil, &ClosingError{"ExecuteCommand failed. The client is closed."}
}
Expand Down Expand Up @@ -436,6 +441,24 @@ func (client *baseClient) HStrLen(key string, field string) (Result[int64], erro
return handleLongResponse(result)
}

func (client *baseClient) HIncrBy(key string, field string, increment int64) (Result[int64], error) {
result, err := client.executeCommand(C.HIncrBy, []string{key, field, utils.IntToString(increment)})
if err != nil {
return CreateNilInt64Result(), err
}

return handleLongResponse(result)
}

func (client *baseClient) HIncrByFloat(key string, field string, increment float64) (Result[float64], error) {
result, err := client.executeCommand(C.HIncrByFloat, []string{key, field, utils.FloatToString(increment)})
if err != nil {
return CreateNilFloat64Result(), err
}

return handleDoubleResponse(result)
}

func (client *baseClient) LPush(key string, elements []string) (Result[int64], error) {
result, err := client.executeCommand(C.LPush, append([]string{key}, elements...))
if err != nil {
Expand Down Expand Up @@ -662,6 +685,39 @@ func (client *baseClient) SUnion(keys []string) (map[Result[string]]struct{}, er
return handleStringSetResponse(result)
}

func (client *baseClient) SScan(key string, cursor string) (Result[string], []Result[string], error) {
result, err := client.executeCommand(C.SScan, []string{key, cursor})
if err != nil {
return CreateNilStringResult(), nil, err
}
return handleScanResponse(result)
}

func (client *baseClient) SScanWithOptions(
key string,
cursor string,
options *BaseScanOptions,
) (Result[string], []Result[string], error) {
optionArgs, err := options.toArgs()
if err != nil {
return CreateNilStringResult(), nil, err
}

result, err := client.executeCommand(C.SScan, append([]string{key, cursor}, optionArgs...))
if err != nil {
return CreateNilStringResult(), nil, err
}
return handleScanResponse(result)
}

func (client *baseClient) SMove(source string, destination string, member string) (Result[bool], error) {
result, err := client.executeCommand(C.SMove, []string{source, destination, member})
if err != nil {
return CreateNilBoolResult(), err
}
return handleBooleanResponse(result)
}

func (client *baseClient) LRange(key string, start int64, end int64) ([]Result[string], error) {
result, err := client.executeCommand(C.LRange, []string{key, utils.IntToString(start), utils.IntToString(end)})
if err != nil {
Expand Down Expand Up @@ -736,7 +792,10 @@ func (client *baseClient) LInsert(
return CreateNilInt64Result(), err
}

result, err := client.executeCommand(C.LInsert, []string{key, insertPositionStr, pivot, element})
result, err := client.executeCommand(
C.LInsert,
[]string{key, insertPositionStr, pivot, element},
)
if err != nil {
return CreateNilInt64Result(), err
}
Expand Down Expand Up @@ -1171,3 +1230,89 @@ func (client *baseClient) Renamenx(key string, newKey string) (Result[bool], err
}
return handleBooleanResponse(result)
}

func (client *baseClient) ZAdd(
key string,
membersScoreMap map[string]float64,
) (Result[int64], error) {
result, err := client.executeCommand(
C.ZAdd,
append([]string{key}, utils.ConvertMapToValueKeyStringArray(membersScoreMap)...),
)
if err != nil {
return CreateNilInt64Result(), err
}

return handleLongResponse(result)
}

func (client *baseClient) ZAddWithOptions(
key string,
membersScoreMap map[string]float64,
opts *options.ZAddOptions,
) (Result[int64], error) {
optionArgs, err := opts.ToArgs()
if err != nil {
return CreateNilInt64Result(), err
}
commandArgs := append([]string{key}, optionArgs...)
result, err := client.executeCommand(
C.ZAdd,
append(commandArgs, utils.ConvertMapToValueKeyStringArray(membersScoreMap)...),
)
if err != nil {
return CreateNilInt64Result(), err
}

return handleLongResponse(result)
}

func (client *baseClient) zAddIncrBase(key string, opts *options.ZAddOptions) (Result[float64], error) {
optionArgs, err := opts.ToArgs()
if err != nil {
return CreateNilFloat64Result(), err
}

result, err := client.executeCommand(C.ZAdd, append([]string{key}, optionArgs...))
if err != nil {
return CreateNilFloat64Result(), err
}

return handleDoubleResponse(result)
}

func (client *baseClient) ZAddIncr(
key string,
member string,
increment float64,
) (Result[float64], error) {
options, err := options.NewZAddOptionsBuilder().SetIncr(true, increment, member)
if err != nil {
return CreateNilFloat64Result(), err
}

return client.zAddIncrBase(key, options)
}

func (client *baseClient) ZAddIncrWithOptions(
key string,
member string,
increment float64,
opts *options.ZAddOptions,
) (Result[float64], error) {
incrOpts, err := opts.SetIncr(true, increment, member)
if err != nil {
return CreateNilFloat64Result(), err
}

return client.zAddIncrBase(key, incrOpts)
}

func (client *baseClient) ZIncrBy(key string, increment float64, member string) (Result[float64], error) {
result, err := client.executeCommand(C.ZIncrBy, []string{key, utils.FloatToString(increment), member})
if err != nil {
return CreateNilFloat64Result(), err
}

return handleDoubleResponse(result)
}
Loading

0 comments on commit f72a04b

Please sign in to comment.