Skip to content

Commit cd47349

Browse files
author
Runze Cui
committed
Add existing code change to support dcc with v9.6.1
1 parent 034a7da commit cd47349

12 files changed

+2084
-75
lines changed

README.md

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Redis client for Go
22

33
[![build workflow](https://github.com/redis/go-redis/actions/workflows/build.yml/badge.svg)](https://github.com/redis/go-redis/actions)
4-
[![PkgGoDev](https://pkg.go.dev/badge/github.com/redis/go-redis/v9)](https://pkg.go.dev/github.com/redis/go-redis/v9?tab=doc)
4+
[![PkgGoDev](https://pkg.go.dev/badge/gitlab.myteksi.net/dbops/Redis/v9)](https://pkg.go.dev/gitlab.myteksi.net/dbops/Redis/v9?tab=doc)
55
[![Documentation](https://img.shields.io/badge/redis-documentation-informational)](https://redis.uptrace.dev/)
66
[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)
77

@@ -36,8 +36,8 @@
3636

3737
- [Discussions](https://github.com/redis/go-redis/discussions)
3838
- [Chat](https://discord.gg/rWtp5Aj)
39-
- [Reference](https://pkg.go.dev/github.com/redis/go-redis/v9)
40-
- [Examples](https://pkg.go.dev/github.com/redis/go-redis/v9#pkg-examples)
39+
- [Reference](https://pkg.go.dev/gitlab.myteksi.net/dbops/Redis/v9)
40+
- [Examples](https://pkg.go.dev/gitlab.myteksi.net/dbops/Redis/v9#pkg-examples)
4141

4242
## Ecosystem
4343

@@ -75,7 +75,7 @@ go mod init github.com/my/repo
7575
Then install go-redis/**v9**:
7676

7777
```shell
78-
go get github.com/redis/go-redis/v9
78+
go get gitlab.myteksi.net/dbops/Redis/v9
7979
```
8080

8181
## Quickstart
@@ -85,7 +85,7 @@ import (
8585
"context"
8686
"fmt"
8787

88-
"github.com/redis/go-redis/v9"
88+
"gitlab.myteksi.net/dbops/Redis/v9"
8989
)
9090

9191
var ctx = context.Background()
@@ -143,7 +143,10 @@ to this specification.
143143

144144
```go
145145
import (
146-
"github.com/redis/go-redis/v9"
146+
"context"
147+
"fmt"
148+
149+
"gitlab.myteksi.net/dbops/Redis/v9"
147150
)
148151

149152
func ExampleClient() *redis.Client {
@@ -158,30 +161,6 @@ func ExampleClient() *redis.Client {
158161

159162
```
160163

161-
162-
### Advanced Configuration
163-
164-
go-redis supports extending the client identification phase to allow projects to send their own custom client identification.
165-
166-
#### Default Client Identification
167-
168-
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.
169-
170-
#### Disabling Identity Verification
171-
172-
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.
173-
174-
To disable verification, set the `DisableIndentity` option to `true` in the Redis client options:
175-
176-
```go
177-
rdb := redis.NewClient(&redis.Options{
178-
Addr: "localhost:6379",
179-
Password: "",
180-
DB: 0,
181-
DisableIndentity: true, // Disable set-info on connect
182-
})
183-
```
184-
185164
## Contributing
186165

187166
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!

cluster_dynamic.go

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
package redis
2+
3+
import (
4+
"context"
5+
"crypto/tls"
6+
"runtime"
7+
"time"
8+
9+
"gitlab.myteksi.net/dbops/Redis/v9/internal"
10+
)
11+
12+
// NewDynamicClusterClient is similar to NewClusterClient, but it supports dynamic connection pool management
13+
// in exiting clients if NewClient option is not specific in ClusterOptions
14+
func NewDynamicClusterClient(opt *ClusterOptions) *ClusterClient {
15+
if opt.NewClient == nil {
16+
opt.NewClient = NewDynamicClient
17+
}
18+
19+
return NewClusterClient(opt)
20+
}
21+
22+
func (c *ClusterClient) SetMaxRedirects(maxRedirects int) {
23+
if maxRedirects == -1 {
24+
maxRedirects = 0
25+
} else if maxRedirects == 0 {
26+
maxRedirects = 3
27+
}
28+
29+
c.opt.MaxRedirects = maxRedirects
30+
}
31+
32+
func (c *ClusterClient) SetReadOnly(readOnly bool) {
33+
c.opt.ReadOnly = readOnly
34+
}
35+
36+
func (c *ClusterClient) SetRouteByLatency(routeByLatency bool) {
37+
if routeByLatency {
38+
c.opt.ReadOnly = true
39+
for _, node := range c.nodes.nodes {
40+
go node.updateLatency()
41+
}
42+
}
43+
c.opt.RouteByLatency = routeByLatency
44+
}
45+
46+
func (c *ClusterClient) SetRouteRandomly(routeRandomly bool) {
47+
if routeRandomly {
48+
c.opt.ReadOnly = true
49+
}
50+
c.opt.RouteRandomly = routeRandomly
51+
}
52+
53+
func (c *ClusterClient) SetUsername(username string) {
54+
if err := c.applyUpdateFn(func(client *Client) {
55+
client.SetUsername(username)
56+
}); err != nil {
57+
internal.Logger.Printf(context.Background(), "SetUsername failed: %s", err)
58+
return
59+
}
60+
61+
c.opt.Username = username
62+
}
63+
64+
func (c *ClusterClient) SetPassword(password string) {
65+
if err := c.applyUpdateFn(func(client *Client) {
66+
client.SetPassword(password)
67+
}); err != nil {
68+
internal.Logger.Printf(context.Background(), "SetPassword failed: %s", err)
69+
return
70+
}
71+
72+
c.opt.Password = password
73+
}
74+
75+
func (c *ClusterClient) SetMaxRetries(maxRetries int) {
76+
if maxRetries == 0 {
77+
maxRetries = -1
78+
}
79+
80+
if err := c.applyUpdateFn(func(client *Client) {
81+
client.SetMaxRetries(maxRetries)
82+
}); err != nil {
83+
internal.Logger.Printf(context.Background(), "SetMaxRetries failed: %s", err)
84+
return
85+
}
86+
87+
c.opt.MaxRetries = maxRetries
88+
}
89+
90+
func (c *ClusterClient) SetMinRetryBackoff(minRetryBackoff time.Duration) {
91+
if minRetryBackoff == -1 {
92+
minRetryBackoff = 0
93+
} else if minRetryBackoff == 0 {
94+
minRetryBackoff = 8 * time.Millisecond
95+
}
96+
97+
if err := c.applyUpdateFn(func(client *Client) {
98+
client.SetMinRetryBackoff(minRetryBackoff)
99+
}); err != nil {
100+
internal.Logger.Printf(context.Background(), "SetMinRetryBackoff failed: %s", err)
101+
return
102+
}
103+
104+
c.opt.MinRetryBackoff = minRetryBackoff
105+
}
106+
107+
func (c *ClusterClient) SetMaxRetryBackoff(maxRetryBackoff time.Duration) {
108+
if maxRetryBackoff == -1 {
109+
maxRetryBackoff = 0
110+
} else if maxRetryBackoff == 0 {
111+
maxRetryBackoff = 512 * time.Millisecond
112+
}
113+
114+
if err := c.applyUpdateFn(func(client *Client) {
115+
client.SetMaxRetryBackoff(maxRetryBackoff)
116+
}); err != nil {
117+
internal.Logger.Printf(context.Background(), "SetMaxRetryBackoff failed: %s", err)
118+
return
119+
}
120+
121+
c.opt.MaxRetryBackoff = maxRetryBackoff
122+
}
123+
124+
func (c *ClusterClient) SetDialTimeout(dialTimeout time.Duration) {
125+
if err := c.applyUpdateFn(func(client *Client) {
126+
client.SetDialTimeout(dialTimeout)
127+
}); err != nil {
128+
internal.Logger.Printf(context.Background(), "SetDialTimeout failed: %s", err)
129+
return
130+
}
131+
132+
c.opt.DialTimeout = dialTimeout
133+
}
134+
135+
func (c *ClusterClient) SetReadTimeout(readTimeout time.Duration) {
136+
if readTimeout == -1 {
137+
readTimeout = 0
138+
} else if readTimeout == 0 {
139+
readTimeout = 3 * time.Second
140+
}
141+
142+
if err := c.applyUpdateFn(func(client *Client) {
143+
client.SetReadTimeout(readTimeout)
144+
}); err != nil {
145+
internal.Logger.Printf(context.Background(), "SetReadTimeout failed: %s", err)
146+
return
147+
}
148+
149+
c.opt.ReadTimeout = readTimeout
150+
}
151+
152+
func (c *ClusterClient) SetWriteTimeout(writeTimeout time.Duration) {
153+
if writeTimeout == -1 {
154+
writeTimeout = 0
155+
} else if writeTimeout == 0 {
156+
writeTimeout = c.opt.ReadTimeout
157+
}
158+
159+
if err := c.applyUpdateFn(func(client *Client) {
160+
client.SetWriteTimeout(writeTimeout)
161+
}); err != nil {
162+
internal.Logger.Printf(context.Background(), "SetWriteTimeout failed: %s", err)
163+
return
164+
}
165+
166+
c.opt.WriteTimeout = writeTimeout
167+
}
168+
169+
func (c *ClusterClient) SetPoolFIFO(poolFIFO bool) {
170+
if err := c.applyUpdateFn(func(client *Client) {
171+
client.SetPoolFIFO(poolFIFO)
172+
}); err != nil {
173+
internal.Logger.Printf(context.Background(), "SetPoolFIFO failed: %s", err)
174+
return
175+
}
176+
177+
c.opt.PoolFIFO = poolFIFO
178+
}
179+
180+
func (c *ClusterClient) SetPoolSize(poolSize int) {
181+
if poolSize == 0 {
182+
poolSize = 5 * runtime.GOMAXPROCS(0)
183+
}
184+
185+
if err := c.applyUpdateFn(func(client *Client) {
186+
client.SetPoolSize(poolSize)
187+
}); err != nil {
188+
internal.Logger.Printf(context.Background(), "SetPoolSize failed: %s", err)
189+
return
190+
}
191+
192+
c.opt.PoolSize = poolSize
193+
}
194+
195+
func (c *ClusterClient) SetMinIdleConns(minIdleConns int) {
196+
if err := c.applyUpdateFn(func(client *Client) {
197+
client.SetMinIdleConns(minIdleConns)
198+
}); err != nil {
199+
internal.Logger.Printf(context.Background(), "SetMinIdleConns failed: %s", err)
200+
return
201+
}
202+
203+
c.opt.MinIdleConns = minIdleConns
204+
}
205+
206+
func (c *ClusterClient) SetMaxIdleConns(maxIdleConns int) {
207+
if err := c.applyUpdateFn(func(client *Client) {
208+
client.SetMaxIdleConns(maxIdleConns)
209+
}); err != nil {
210+
internal.Logger.Printf(context.Background(), "SetMaxIdleConns failed: %s", err)
211+
return
212+
}
213+
214+
c.opt.MaxIdleConns = maxIdleConns
215+
}
216+
217+
func (c *ClusterClient) SetConnMaxLifetime(connMaxLifetime time.Duration) {
218+
if err := c.applyUpdateFn(func(client *Client) {
219+
client.SetConnMaxLifetime(connMaxLifetime)
220+
}); err != nil {
221+
internal.Logger.Printf(context.Background(), "SetConnMaxLifetimefailed: %s", err)
222+
return
223+
}
224+
225+
c.opt.ConnMaxLifetime = connMaxLifetime
226+
}
227+
228+
func (c *ClusterClient) SetPoolTimeout(poolTimeout time.Duration) {
229+
if err := c.applyUpdateFn(func(client *Client) {
230+
client.SetPoolTimeout(poolTimeout)
231+
}); err != nil {
232+
internal.Logger.Printf(context.Background(), "SetPoolTimeout failed: %s", err)
233+
return
234+
}
235+
236+
c.opt.PoolTimeout = poolTimeout
237+
}
238+
239+
func (c *ClusterClient) SetConnMaxIdleTimeout(idleTimeout time.Duration) {
240+
if err := c.applyUpdateFn(func(client *Client) {
241+
client.SetConnMaxIdleTime(idleTimeout)
242+
}); err != nil {
243+
internal.Logger.Printf(context.Background(), "SetIdleTimeout failed: %s", err)
244+
return
245+
}
246+
247+
c.opt.ConnMaxIdleTime = idleTimeout
248+
}
249+
250+
func (c *ClusterClient) SetTLSConfig(tlsConfig *tls.Config) {
251+
if err := c.applyUpdateFn(func(client *Client) {
252+
client.SetTLSConfig(tlsConfig)
253+
}); err != nil {
254+
internal.Logger.Printf(context.Background(), "SetTLSConfig failed: %s", err)
255+
return
256+
}
257+
258+
c.opt.TLSConfig = tlsConfig
259+
}
260+
261+
func (c *ClusterClient) applyUpdateFn(fn func(client *Client)) error {
262+
nodes, err := c.nodes.All()
263+
if err != nil {
264+
return err
265+
}
266+
267+
for _, node := range nodes {
268+
fn(node.Client)
269+
}
270+
return nil
271+
}

0 commit comments

Comments
 (0)