Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekshenawa committed Mar 21, 2024
2 parents a77a6bb + 8b15101 commit 24d834f
Show file tree
Hide file tree
Showing 9 changed files with 563 additions and 466 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.20.x, 1.21.x]
go-version: [1.19.x, 1.20.x, 1.21.x]

services:
redis:
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/test-redis-enterprise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
go-version: [1.21.x]
re-build: ["7.2.4-108"]
re-build: ["7.4.2-54"]

steps:
- name: Checkout code
Expand All @@ -36,14 +36,12 @@ jobs:
- name: Build cluster
working-directory: redis-ee
env:
IMAGE: "redislabs/redis-internal:${{ matrix.re-build }}"
RE_USERNAME: ${{ secrets.RE_USERNAME }}
RE_PASS: ${{ secrets.RE_PASS }}
RE_CLUSTER_NAME: ${{ secrets.RE_CLUSTER_NAME }}
IMAGE: "redislabs/redis:${{ matrix.re-build }}"
RE_USERNAME: test@test.com
RE_PASS: 12345
RE_CLUSTER_NAME: re-test
RE_USE_OSS_CLUSTER: false
RE_DB_PORT: ${{ secrets.RE_DB_PORT }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
RE_DB_PORT: 6379
run: ./build.sh

- name: Test
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)

test: testdeps
$(eval GO_VERSION := $(shell go version | cut -d " " -f 3 | cut -d. -f2))
set -e; for dir in $(GO_MOD_DIRS); do \
if echo "$${dir}" | grep -q "./example" && [ "$(GO_VERSION)" = "19" ]; then \
echo "Skipping go test in $${dir} due to Go version 1.19 and dir contains ./example"; \
continue; \
fi; \
echo "go test in $${dir}"; \
(cd "$${dir}" && \
go mod tidy -compat=1.18 && \
Expand Down
5 changes: 4 additions & 1 deletion command.go
Original file line number Diff line number Diff line change
Expand Up @@ -5454,9 +5454,12 @@ func (cmd *MonitorCmd) readMonitor(rd *proto.Reader, cancel context.CancelFunc)
for {
cmd.mu.Lock()
st := cmd.status
pk, _ := rd.Peek(1)
cmd.mu.Unlock()
if pk, _ := rd.Peek(1); len(pk) != 0 && st == monitorStatusStart {
if len(pk) != 0 && st == monitorStatusStart {
cmd.mu.Lock()
line, err := rd.ReadString()
cmd.mu.Unlock()
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions example/otel/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ require (
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.1 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.46.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.43.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.44.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
Expand All @@ -43,5 +41,5 @@ require (
google.golang.org/genproto/googleapis/api v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240108191215-35c7eff3a6b1 // indirect
google.golang.org/grpc v1.60.1 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
454 changes: 5 additions & 449 deletions example/otel/go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extra/redisprometheus/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ require (
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
golang.org/x/sys v0.4.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
)
491 changes: 488 additions & 3 deletions extra/redisprometheus/go.sum

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package redis_test

import (
"context"
"strings"
"time"

"testing"

. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"

Expand Down Expand Up @@ -46,3 +49,52 @@ var _ = Describe("Monitor command", Label("monitor"), func() {
Expect(lst[3]).To(ContainSubstring(`"set" "bap" "8"`))
})
})

func TestMonitorCommand(t *testing.T) {
ctx := context.TODO()
client := redis.NewClient(&redis.Options{Addr: ":6379"})
if err := client.FlushDB(ctx).Err(); err != nil {
t.Fatalf("FlushDB failed: %v", err)
}

defer func() {
if err := client.Close(); err != nil {
t.Fatalf("Close failed: %v", err)
}
}()

ress := make(chan string, 10) // Buffer to prevent blocking
client1 := redis.NewClient(&redis.Options{Addr: ":6379"}) // Adjust the Addr field as necessary
mn := client1.Monitor(ctx, ress)
mn.Start()
// Wait for the Redis server to be in monitoring mode.
time.Sleep(100 * time.Millisecond)
client.Set(ctx, "foo", "bar", 0)
client.Set(ctx, "bar", "baz", 0)
client.Set(ctx, "bap", 8, 0)
client.Get(ctx, "bap")
mn.Stop()
var lst []string
for i := 0; i < 5; i++ {
s := <-ress
lst = append(lst, s)
}

// Assertions
if !containsSubstring(lst[0], "OK") {
t.Errorf("Expected lst[0] to contain 'OK', got %s", lst[0])
}
if !containsSubstring(lst[1], `"set" "foo" "bar"`) {
t.Errorf(`Expected lst[1] to contain '"set" "foo" "bar"', got %s`, lst[1])
}
if !containsSubstring(lst[2], `"set" "bar" "baz"`) {
t.Errorf(`Expected lst[2] to contain '"set" "bar" "baz"', got %s`, lst[2])
}
if !containsSubstring(lst[3], `"set" "bap" "8"`) {
t.Errorf(`Expected lst[3] to contain '"set" "bap" "8"', got %s`, lst[3])
}
}

func containsSubstring(s, substr string) bool {
return strings.Contains(s, substr)
}

0 comments on commit 24d834f

Please sign in to comment.