Skip to content

Commit

Permalink
merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
ofekshenawa committed Feb 14, 2024
2 parents a118fe6 + 21ed15b commit 7f4c593
Show file tree
Hide file tree
Showing 20 changed files with 380 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version: [1.19.x, 1.20.x, 1.21.x]
go-version: [1.20.x, 1.21.x]

services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Expand Up @@ -23,4 +23,4 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
# Drafts your next Release notes as Pull Requests are merged into "master"
- uses: release-drafter/release-drafter@v5
- uses: release-drafter/release-drafter@v6
with:
# (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml
config-name: release-drafter-config.yml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/spellcheck.yml
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Check Spelling
uses: rojopolis/spellcheck-github-actions@0.35.0
uses: rojopolis/spellcheck-github-actions@0.36.0
with:
config_path: .github/spellcheck-settings.yml
task_name: Markdown
2 changes: 1 addition & 1 deletion .github/workflows/test-redis-enterprise.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
fail-fast: false
matrix:
go-version: [1.21.x]
re-build: ["7.2.4-92"]
re-build: ["7.2.4-108"]

steps:
- name: Checkout code
Expand Down
14 changes: 14 additions & 0 deletions bitmap_commands.go
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"context"
"errors"
)

type BitMapCmdable interface {
Expand Down Expand Up @@ -37,15 +38,28 @@ func (c cmdable) SetBit(ctx context.Context, key string, offset int64, value int

type BitCount struct {
Start, End int64
Unit string // BYTE(default) | BIT
}

const BitCountIndexByte string = "BYTE"
const BitCountIndexBit string = "BIT"

func (c cmdable) BitCount(ctx context.Context, key string, bitCount *BitCount) *IntCmd {
args := []interface{}{"bitcount", key}
if bitCount != nil {
if bitCount.Unit == "" {
bitCount.Unit = "BYTE"
}
if bitCount.Unit != BitCountIndexByte && bitCount.Unit != BitCountIndexBit {
cmd := NewIntCmd(ctx)
cmd.SetErr(errors.New("redis: invalid bitcount index"))
return cmd
}
args = append(
args,
bitCount.Start,
bitCount.End,
string(bitCount.Unit),
)
}
cmd := NewIntCmd(ctx, args...)
Expand Down
98 changes: 98 additions & 0 deletions bitmap_commands_test.go
@@ -0,0 +1,98 @@
package redis_test

import (
. "github.com/bsm/ginkgo/v2"
. "github.com/bsm/gomega"
"github.com/redis/go-redis/v9"
)

type bitCountExpected struct {
Start int64
End int64
Expected int64
}

var _ = Describe("BitCountBite", func() {
var client *redis.Client
key := "bit_count_test"

BeforeEach(func() {
client = redis.NewClient(redisOptions())
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
values := []int{0, 1, 0, 0, 1, 0, 1, 0, 1, 1}
for i, v := range values {
cmd := client.SetBit(ctx, key, int64(i), v)
Expect(cmd.Err()).NotTo(HaveOccurred())
}
})

AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})

It("bit count bite", func() {
var expected = []bitCountExpected{
{0, 0, 0},
{0, 1, 1},
{0, 2, 1},
{0, 3, 1},
{0, 4, 2},
{0, 5, 2},
{0, 6, 3},
{0, 7, 3},
{0, 8, 4},
{0, 9, 5},
}

for _, e := range expected {
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End, Unit: redis.BitCountIndexBit})
Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.Val()).To(Equal(e.Expected))
}
})
})

var _ = Describe("BitCountByte", func() {
var client *redis.Client
key := "bit_count_test"

BeforeEach(func() {
client = redis.NewClient(redisOptions())
Expect(client.FlushDB(ctx).Err()).NotTo(HaveOccurred())
values := []int{0, 0, 0, 0, 0, 0, 0, 1, 1, 1}
for i, v := range values {
cmd := client.SetBit(ctx, key, int64(i), v)
Expect(cmd.Err()).NotTo(HaveOccurred())
}
})

AfterEach(func() {
Expect(client.Close()).NotTo(HaveOccurred())
})

It("bit count byte", func() {
var expected = []bitCountExpected{
{0, 0, 1},
{0, 1, 3},
}

for _, e := range expected {
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End, Unit: redis.BitCountIndexByte})
Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.Val()).To(Equal(e.Expected))
}
})

It("bit count byte with no unit specified", func() {
var expected = []bitCountExpected{
{0, 0, 1},
{0, 1, 3},
}

for _, e := range expected {
cmd := client.BitCount(ctx, key, &redis.BitCount{Start: e.Start, End: e.End})
Expect(cmd.Err()).NotTo(HaveOccurred())
Expect(cmd.Val()).To(Equal(e.Expected))
}
})
})
10 changes: 10 additions & 0 deletions command.go
Expand Up @@ -5310,6 +5310,16 @@ type LibraryInfo struct {
LibVer *string
}

// WithLibraryName returns a valid LibraryInfo with library name only.
func WithLibraryName(libName string) LibraryInfo {
return LibraryInfo{LibName: &libName}
}

// WithLibraryVersion returns a valid LibraryInfo with library version only.
func WithLibraryVersion(libVer string) LibraryInfo {
return LibraryInfo{LibVer: &libVer}
}

// -------------------------------------------

type InfoCmd struct {
Expand Down
4 changes: 2 additions & 2 deletions commands_test.go
Expand Up @@ -248,7 +248,7 @@ var _ = Describe("Commands", func() {

// Test setting the libName
libName := "go-redis"
libInfo := redis.LibraryInfo{LibName: &libName}
libInfo := redis.WithLibraryName(libName)
setInfo := pipe.ClientSetInfo(ctx, libInfo)
_, err := pipe.Exec(ctx)

Expand All @@ -258,7 +258,7 @@ var _ = Describe("Commands", func() {

// Test setting the libVer
libVer := "vX.x"
libInfo = redis.LibraryInfo{LibVer: &libVer}
libInfo = redis.WithLibraryVersion(libVer)
setInfo = pipe.ClientSetInfo(ctx, libInfo)
_, err = pipe.Exec(ctx)

Expand Down
20 changes: 10 additions & 10 deletions example/otel/config/otel-collector.yaml
Expand Up @@ -30,18 +30,18 @@ receivers:
processors:
resourcedetection:
detectors: ['system']
cumulativetodelta:
batch:
send_batch_size: 10000
timeout: 10s

exporters:
logging:
logLevel: debug
otlp:
endpoint: uptrace:14317
otlp/uptrace:
endpoint: http://uptrace:14317
tls:
insecure: true
headers: { 'uptrace-dsn': 'http://project2_secret_token@localhost:14317/2' }
debug:

service:
# telemetry:
Expand All @@ -51,18 +51,18 @@ service:
traces:
receivers: [otlp, jaeger]
processors: [batch]
exporters: [otlp, logging]
exporters: [otlp/uptrace]
metrics:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
processors: [cumulativetodelta, batch]
exporters: [otlp/uptrace]
metrics/hostmetrics:
receivers: [hostmetrics, redis]
processors: [batch, resourcedetection]
exporters: [otlp]
processors: [cumulativetodelta, batch, resourcedetection]
exporters: [otlp/uptrace]
logs:
receivers: [otlp]
processors: [batch]
exporters: [otlp]
exporters: [otlp/uptrace]

extensions: [health_check, pprof, zpages]
6 changes: 3 additions & 3 deletions example/otel/docker-compose.yml
Expand Up @@ -2,7 +2,7 @@ version: '3'

services:
clickhouse:
image: clickhouse/clickhouse-server:22.10
image: clickhouse/clickhouse-server:23.7
restart: on-failure
environment:
CLICKHOUSE_DB: uptrace
Expand Down Expand Up @@ -36,7 +36,7 @@ services:
- '5432:5432'

uptrace:
image: 'uptrace/uptrace:1.5.0'
image: 'uptrace/uptrace:1.6.2'
#image: 'uptrace/uptrace-dev:latest'
restart: on-failure
volumes:
Expand All @@ -51,7 +51,7 @@ services:
condition: service_healthy

otelcol:
image: otel/opentelemetry-collector-contrib:0.70.0
image: otel/opentelemetry-collector-contrib:0.91.0
restart: on-failure
volumes:
- ./config/otel-collector.yaml:/etc/otelcol-contrib/config.yaml
Expand Down
46 changes: 24 additions & 22 deletions example/otel/go.mod
Expand Up @@ -11,35 +11,37 @@ replace github.com/redis/go-redis/extra/rediscmd/v9 => ../../extra/rediscmd
require (
github.com/redis/go-redis/extra/redisotel/v9 v9.4.0
github.com/redis/go-redis/v9 v9.4.0
github.com/uptrace/uptrace-go v1.16.0
go.opentelemetry.io/otel v1.16.0
github.com/uptrace/uptrace-go v1.21.0
go.opentelemetry.io/otel v1.21.0
)

require (
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.4.0 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.39.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.30.0 // 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
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20240108191215-35c7eff3a6b1 // indirect
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
)

0 comments on commit 7f4c593

Please sign in to comment.