Skip to content

Commit

Permalink
Merge branch 'master' into feat/max_cmd_bytes_otel
Browse files Browse the repository at this point in the history
  • Loading branch information
rfyiamcool committed Feb 29, 2024
2 parents 27e64d4 + d43a9fa commit af53666
Show file tree
Hide file tree
Showing 18 changed files with 83 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/wordlist.txt
Expand Up @@ -2,6 +2,7 @@ ACLs
autoload
autoloader
autoloading
analytics
Autoloading
backend
backends
Expand All @@ -13,6 +14,7 @@ customizable
Customizable
dataset
de
DisableIdentity
ElastiCache
extensibility
FPM
Expand Down Expand Up @@ -43,6 +45,7 @@ RocksDB
runtime
SHA
sharding
SETNAME
SSL
struct
stunnel
Expand Down
24 changes: 24 additions & 0 deletions README.md
Expand Up @@ -161,6 +161,30 @@ func ExampleClient() *redis.Client {

```


### Advanced Configuration

go-redis supports extending the client identification phase to allow projects to send their own custom client identification.

#### Default Client Identification

By default, go-redis automatically sends the client library name and version during the connection process. This feature is available in redis-server as of version 7.2. As a result, the command is "fire and forget", meaning it should fail silently, in the case that the redis server does not support this feature.

#### Disabling Identity Verification

When connection identity verification is not required or needs to be explicitly disabled, a `DisableIndentity` configuration option exists. In V10 of this library, `DisableIndentity` will become `DisableIdentity` in order to fix the associated typo.

To disable verification, set the `DisableIndentity` option to `true` in the Redis client options:

```go
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0,
DisableIndentity: true, // Disable set-info on connect
})
```

## Contributing

Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Expand Up @@ -309,7 +309,7 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S

var cmd *StatusCmd
if info.LibName != nil {
libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version())
libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, internal.ReplaceSpaces(runtime.Version()))
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName)
} else {
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer)
Expand Down
4 changes: 2 additions & 2 deletions commands_test.go
Expand Up @@ -2105,7 +2105,7 @@ var _ = Describe("Commands", func() {

logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(1))
Expect(len(logEntries)).To(Equal(4))

for _, entry := range logEntries {
Expect(entry.Reason).To(Equal("command"))
Expand All @@ -2121,7 +2121,7 @@ var _ = Describe("Commands", func() {

limitedLogEntries, err := client.ACLLog(ctx, 2).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(limitedLogEntries)).To(Equal(1))
Expect(len(limitedLogEntries)).To(Equal(2))
})

It("should ACL LOG RESET", Label("NonRedisEnterprise"), func() {
Expand Down
2 changes: 1 addition & 1 deletion example/del-keys-without-ttl/go.mod
Expand Up @@ -5,7 +5,7 @@ go 1.18
replace github.com/redis/go-redis/v9 => ../..

require (
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.1
go.uber.org/zap v1.24.0
)

Expand Down
2 changes: 1 addition & 1 deletion example/hll/go.mod
Expand Up @@ -4,7 +4,7 @@ go 1.18

replace github.com/redis/go-redis/v9 => ../..

require github.com/redis/go-redis/v9 v9.5.0
require github.com/redis/go-redis/v9 v9.5.1

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion example/lua-scripting/go.mod
Expand Up @@ -4,7 +4,7 @@ go 1.18

replace github.com/redis/go-redis/v9 => ../..

require github.com/redis/go-redis/v9 v9.5.0
require github.com/redis/go-redis/v9 v9.5.1

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
6 changes: 3 additions & 3 deletions example/otel/go.mod
Expand Up @@ -9,8 +9,8 @@ replace github.com/redis/go-redis/extra/redisotel/v9 => ../../extra/redisotel
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../../extra/rediscmd

require (
github.com/redis/go-redis/extra/redisotel/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/extra/redisotel/v9 v9.5.1
github.com/redis/go-redis/v9 v9.5.1
github.com/uptrace/uptrace-go v1.21.0
go.opentelemetry.io/otel v1.21.0
)
Expand All @@ -23,7 +23,7 @@ require (
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.19.0 // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.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
Expand Down
2 changes: 1 addition & 1 deletion example/redis-bloom/go.mod
Expand Up @@ -4,7 +4,7 @@ go 1.18

replace github.com/redis/go-redis/v9 => ../..

require github.com/redis/go-redis/v9 v9.5.0
require github.com/redis/go-redis/v9 v9.5.1

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion example/scan-struct/go.mod
Expand Up @@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..

require (
github.com/davecgh/go-spew v1.1.1
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.1
)

require (
Expand Down
4 changes: 2 additions & 2 deletions extra/rediscensus/go.mod
Expand Up @@ -8,7 +8,7 @@ replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd

require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.1
github.com/redis/go-redis/v9 v9.5.1
go.opencensus.io v0.24.0
)
2 changes: 1 addition & 1 deletion extra/rediscmd/go.mod
Expand Up @@ -7,5 +7,5 @@ replace github.com/redis/go-redis/v9 => ../..
require (
github.com/bsm/ginkgo/v2 v2.7.0
github.com/bsm/gomega v1.26.0
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.1
)
4 changes: 2 additions & 2 deletions extra/redisotel/go.mod
Expand Up @@ -7,8 +7,8 @@ replace github.com/redis/go-redis/v9 => ../..
replace github.com/redis/go-redis/extra/rediscmd/v9 => ../rediscmd

require (
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/extra/rediscmd/v9 v9.5.1
github.com/redis/go-redis/v9 v9.5.1
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
Expand Down
2 changes: 1 addition & 1 deletion extra/redisprometheus/go.mod
Expand Up @@ -6,7 +6,7 @@ replace github.com/redis/go-redis/v9 => ../..

require (
github.com/prometheus/client_golang v1.14.0
github.com/redis/go-redis/v9 v9.5.0
github.com/redis/go-redis/v9 v9.5.1
)

require (
Expand Down
20 changes: 20 additions & 0 deletions internal/util.go
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"context"
"strings"
"time"

"github.com/redis/go-redis/v9/internal/util"
Expand Down Expand Up @@ -44,3 +45,22 @@ func isLower(s string) bool {
}
return true
}

func ReplaceSpaces(s string) string {
// Pre-allocate a builder with the same length as s to minimize allocations.
// This is a basic optimization; adjust the initial size based on your use case.
var builder strings.Builder
builder.Grow(len(s))

for _, char := range s {
if char == ' ' {
// Replace space with a hyphen.
builder.WriteRune('-')
} else {
// Copy the character as-is.
builder.WriteRune(char)
}
}

return builder.String()
}
22 changes: 12 additions & 10 deletions redis.go
Expand Up @@ -334,22 +334,24 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
pipe.ClientSetName(ctx, c.opt.ClientName)
}

if !c.opt.DisableIndentity {
libName := ""
libVer := Version()
if c.opt.IdentitySuffix != "" {
libName = c.opt.IdentitySuffix
}
pipe.ClientSetInfo(ctx, WithLibraryName(libName))
pipe.ClientSetInfo(ctx, WithLibraryVersion(libVer))
}

return nil
})
if err != nil {
return err
}

if !c.opt.DisableIndentity {
libName := ""
libVer := Version()
if c.opt.IdentitySuffix != "" {
libName = c.opt.IdentitySuffix
}
p := conn.Pipeline()
p.ClientSetInfo(ctx, WithLibraryName(libName))
p.ClientSetInfo(ctx, WithLibraryVersion(libVer))
_, _ = p.Exec(ctx)
}

if c.opt.OnConnect != nil {
return c.opt.OnConnect(ctx, conn)
}
Expand Down
6 changes: 6 additions & 0 deletions sentinel.go
Expand Up @@ -153,6 +153,9 @@ func (opt *FailoverOptions) sentinelOptions(addr string) *Options {
ConnMaxLifetime: opt.ConnMaxLifetime,

TLSConfig: opt.TLSConfig,

DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
}
}

Expand Down Expand Up @@ -190,6 +193,9 @@ func (opt *FailoverOptions) clusterOptions() *ClusterOptions {
ConnMaxLifetime: opt.ConnMaxLifetime,

TLSConfig: opt.TLSConfig,

DisableIndentity: opt.DisableIndentity,
IdentitySuffix: opt.IdentitySuffix,
}
}

Expand Down
2 changes: 1 addition & 1 deletion version.go
Expand Up @@ -2,5 +2,5 @@ package redis

// Version is the current release version.
func Version() string {
return "9.5.0"
return "9.5.1"
}

0 comments on commit af53666

Please sign in to comment.