Skip to content

Commit 61c3953

Browse files
authored
Merge branch 'master' into DOC-4439-conn-mgmt-cmd-examples
2 parents 48deafe + 4e22885 commit 61c3953

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+5335
-871
lines changed

.github/actions/run-tests/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ runs:
2525
2626
# Mapping of redis version to redis testing containers
2727
declare -A redis_version_mapping=(
28-
["8.0-M05"]="8.0-M05-pre"
28+
["8.0.1"]="8.0.1-pre"
2929
["7.4.2"]="rs-7.4.0-v2"
3030
["7.2.7"]="rs-7.2.0-v14"
3131
)

.github/wordlist.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Lua
2929
MSSQL
3030
namespace
3131
NoSQL
32+
OpenTelemetry
3233
ORM
3334
Packagist
3435
PhpRedis
@@ -64,4 +65,12 @@ RedisGears
6465
RedisTimeseries
6566
RediSearch
6667
RawResult
67-
RawVal
68+
RawVal
69+
entra
70+
EntraID
71+
Entra
72+
OAuth
73+
Azure
74+
StreamingCredentialsProvider
75+
oauth
76+
entraid

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Go
22

33
on:
44
push:
5-
branches: [master, v9, v9.7]
5+
branches: [master, v9, v9.7, v9.8]
66
pull_request:
7-
branches: [master, v9, v9.7]
7+
branches: [master, v9, v9.7, v9.8]
88

99
permissions:
1010
contents: read
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
redis-version:
21-
- "8.0-M05" # 8.0 milestone 5
21+
- "8.0.1" # 8.0.1
2222
- "7.4.2" # should use redis stack 7.4
2323
go-version:
2424
- "1.23.x"
@@ -43,7 +43,7 @@ jobs:
4343
4444
# Mapping of redis version to redis testing containers
4545
declare -A redis_version_mapping=(
46-
["8.0-M05"]="8.0-M05-pre"
46+
["8.0.1"]="8.0.1-pre"
4747
["7.4.2"]="rs-7.4.0-v2"
4848
)
4949
if [[ -v redis_version_mapping[$REDIS_VERSION] ]]; then
@@ -72,7 +72,7 @@ jobs:
7272
fail-fast: false
7373
matrix:
7474
redis-version:
75-
- "8.0-M05" # 8.0 milestone 5
75+
- "8.0.1" # 8.0.1
7676
- "7.4.2" # should use redis stack 7.4
7777
- "7.2.7" # should redis stack 7.2
7878
go-version:

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ name: "CodeQL"
1313

1414
on:
1515
push:
16-
branches: [ master ]
16+
branches: [master, v9, v9.7, v9.8]
1717
pull_request:
18-
# The branches below must be a subset of the branches above
19-
branches: [ master ]
18+
branches: [master, v9, v9.7, v9.8]
2019

2120
jobs:
2221
analyze:

.github/workflows/golangci-lint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- master
99
- main
1010
- v9
11+
- v9.8
1112
pull_request:
1213

1314
permissions:
@@ -21,4 +22,7 @@ jobs:
2122
steps:
2223
- uses: actions/checkout@v4
2324
- name: golangci-lint
24-
uses: golangci/[email protected]
25+
uses: golangci/[email protected]
26+
with:
27+
verify: true
28+

.github/workflows/spellcheck.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
- name: Checkout
99
uses: actions/checkout@v4
1010
- name: Check Spelling
11-
uses: rojopolis/spellcheck-github-actions@0.47.0
11+
uses: rojopolis/spellcheck-github-actions@0.49.0
1212
with:
1313
config_path: .github/spellcheck-settings.yml
1414
task_name: Markdown

.github/workflows/test-redis-enterprise.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: RE Tests
22

33
on:
44
push:
5-
branches: [master]
5+
branches: [master, v9, v9.7, v9.8]
66
pull_request:
77

88
permissions:
@@ -54,5 +54,4 @@ jobs:
5454
--ginkgo.skip-file="sentinel_test.go" \
5555
--ginkgo.skip-file="osscluster_test.go" \
5656
--ginkgo.skip-file="pubsub_test.go" \
57-
--ginkgo.skip-file="gears_commands_test.go" \
5857
--ginkgo.label-filter='!NonRedisEnterprise'

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ testdata/*
77
redis8tests.sh
88
coverage.txt
99
**/coverage.txt
10-
.vscode
10+
.vscode
11+
tmp/*

.golangci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
version: "2"
12
run:
23
timeout: 5m
34
tests: false
5+
linters:
6+
settings:
7+
staticcheck:
8+
checks:
9+
- all
10+
# Incorrect or missing package comment.
11+
# https://staticcheck.dev/docs/checks/#ST1000
12+
- -ST1000
13+
# Omit embedded fields from selector expression.
14+
# https://staticcheck.dev/docs/checks/#QF1008
15+
- -QF1008
16+
- -ST1003
17+
exclusions:
18+
generated: lax
19+
presets:
20+
- comments
21+
- common-false-positives
22+
- legacy
23+
- std-error-handling
24+
paths:
25+
- third_party$
26+
- builtin$
27+
- examples$
28+
formatters:
29+
exclusions:
30+
generated: lax
31+
paths:
32+
- third_party$
33+
- builtin$
34+
- examples$

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@ The core team regularly looks at pull requests. We will provide
112112
feedback as soon as possible. After receiving our feedback, please respond
113113
within two weeks. After that time, we may close your PR if it isn't
114114
showing any activity.
115+
116+
## Support
117+
118+
Maintainers can provide limited support to contributors on discord: https://discord.gg/W4txy5AeKM

README.md

Lines changed: 158 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
[![build workflow](https://github.com/redis/go-redis/actions/workflows/build.yml/badge.svg)](https://github.com/redis/go-redis/actions)
44
[![PkgGoDev](https://pkg.go.dev/badge/github.com/redis/go-redis/v9)](https://pkg.go.dev/github.com/redis/go-redis/v9?tab=doc)
55
[![Documentation](https://img.shields.io/badge/redis-documentation-informational)](https://redis.uptrace.dev/)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/redis/go-redis/v9)](https://goreportcard.com/report/github.com/redis/go-redis/v9)
67
[![codecov](https://codecov.io/github/redis/go-redis/graph/badge.svg?token=tsrCZKuSSw)](https://codecov.io/github/redis/go-redis)
7-
[![Chat](https://discordapp.com/api/guilds/752070105847955518/widget.png)](https://discord.gg/rWtp5Aj)
8+
9+
[![Discord](https://img.shields.io/discord/697882427875393627.svg?style=social&logo=discord)](https://discord.gg/W4txy5AeKM)
10+
[![Twitch](https://img.shields.io/twitch/status/redisinc?style=social)](https://www.twitch.tv/redisinc)
11+
[![YouTube](https://img.shields.io/youtube/channel/views/UCD78lHSwYqMlyetR0_P4Vig?style=social)](https://www.youtube.com/redisinc)
12+
[![Twitter](https://img.shields.io/twitter/follow/redisinc?style=social)](https://twitter.com/redisinc)
13+
[![Stack Exchange questions](https://img.shields.io/stackexchange/stackoverflow/t/go-redis?style=social&logo=stackoverflow&label=Stackoverflow)](https://stackoverflow.com/questions/tagged/go-redis)
814

915
> go-redis is the official Redis client library for the Go programming language. It offers a straightforward interface for interacting with Redis servers.
1016
@@ -44,7 +50,7 @@ in the `go.mod` to `go 1.24` in one of the next releases.
4450
## Resources
4551

4652
- [Discussions](https://github.com/redis/go-redis/discussions)
47-
- [Chat](https://discord.gg/rWtp5Aj)
53+
- [Chat](https://discord.gg/W4txy5AeKM)
4854
- [Reference](https://pkg.go.dev/github.com/redis/go-redis/v9)
4955
- [Examples](https://pkg.go.dev/github.com/redis/go-redis/v9#pkg-examples)
5056

@@ -62,6 +68,7 @@ key value NoSQL database that uses RocksDB as storage engine and is compatible w
6268

6369
- Redis commands except QUIT and SYNC.
6470
- Automatic connection pooling.
71+
- [StreamingCredentialsProvider (e.g. entra id, oauth)](#1-streaming-credentials-provider-highest-priority) (experimental)
6572
- [Pub/Sub](https://redis.uptrace.dev/guide/go-redis-pubsub.html).
6673
- [Pipelines and transactions](https://redis.uptrace.dev/guide/go-redis-pipelines.html).
6774
- [Scripting](https://redis.uptrace.dev/guide/lua-scripting.html).
@@ -130,17 +137,121 @@ func ExampleClient() {
130137
}
131138
```
132139

133-
The above can be modified to specify the version of the RESP protocol by adding the `protocol`
134-
option to the `Options` struct:
140+
### Authentication
141+
142+
The Redis client supports multiple ways to provide authentication credentials, with a clear priority order. Here are the available options:
143+
144+
#### 1. Streaming Credentials Provider (Highest Priority) - Experimental feature
145+
146+
The streaming credentials provider allows for dynamic credential updates during the connection lifetime. This is particularly useful for managed identity services and token-based authentication.
135147

136148
```go
137-
rdb := redis.NewClient(&redis.Options{
138-
Addr: "localhost:6379",
139-
Password: "", // no password set
140-
DB: 0, // use default DB
141-
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
142-
})
149+
type StreamingCredentialsProvider interface {
150+
Subscribe(listener CredentialsListener) (Credentials, UnsubscribeFunc, error)
151+
}
152+
153+
type CredentialsListener interface {
154+
OnNext(credentials Credentials) // Called when credentials are updated
155+
OnError(err error) // Called when an error occurs
156+
}
157+
158+
type Credentials interface {
159+
BasicAuth() (username string, password string)
160+
RawCredentials() string
161+
}
162+
```
163+
164+
Example usage:
165+
```go
166+
rdb := redis.NewClient(&redis.Options{
167+
Addr: "localhost:6379",
168+
StreamingCredentialsProvider: &MyCredentialsProvider{},
169+
})
170+
```
171+
172+
**Note:** The streaming credentials provider can be used with [go-redis-entraid](https://github.com/redis/go-redis-entraid) to enable Entra ID (formerly Azure AD) authentication. This allows for seamless integration with Azure's managed identity services and token-based authentication.
173+
174+
Example with Entra ID:
175+
```go
176+
import (
177+
"github.com/redis/go-redis/v9"
178+
"github.com/redis/go-redis-entraid"
179+
)
180+
181+
// Create an Entra ID credentials provider
182+
provider := entraid.NewDefaultAzureIdentityProvider()
183+
184+
// Configure Redis client with Entra ID authentication
185+
rdb := redis.NewClient(&redis.Options{
186+
Addr: "your-redis-server.redis.cache.windows.net:6380",
187+
StreamingCredentialsProvider: provider,
188+
TLSConfig: &tls.Config{
189+
MinVersion: tls.VersionTLS12,
190+
},
191+
})
192+
```
193+
194+
#### 2. Context-based Credentials Provider
195+
196+
The context-based provider allows credentials to be determined at the time of each operation, using the context.
197+
198+
```go
199+
rdb := redis.NewClient(&redis.Options{
200+
Addr: "localhost:6379",
201+
CredentialsProviderContext: func(ctx context.Context) (string, string, error) {
202+
// Return username, password, and any error
203+
return "user", "pass", nil
204+
},
205+
})
206+
```
207+
208+
#### 3. Regular Credentials Provider
209+
210+
A simple function-based provider that returns static credentials.
143211

212+
```go
213+
rdb := redis.NewClient(&redis.Options{
214+
Addr: "localhost:6379",
215+
CredentialsProvider: func() (string, string) {
216+
// Return username and password
217+
return "user", "pass"
218+
},
219+
})
220+
```
221+
222+
#### 4. Username/Password Fields (Lowest Priority)
223+
224+
The most basic way to provide credentials is through the `Username` and `Password` fields in the options.
225+
226+
```go
227+
rdb := redis.NewClient(&redis.Options{
228+
Addr: "localhost:6379",
229+
Username: "user",
230+
Password: "pass",
231+
})
232+
```
233+
234+
#### Priority Order
235+
236+
The client will use credentials in the following priority order:
237+
1. Streaming Credentials Provider (if set)
238+
2. Context-based Credentials Provider (if set)
239+
3. Regular Credentials Provider (if set)
240+
4. Username/Password fields (if set)
241+
242+
If none of these are set, the client will attempt to connect without authentication.
243+
244+
### Protocol Version
245+
246+
The client supports both RESP2 and RESP3 protocols. You can specify the protocol version in the options:
247+
248+
```go
249+
rdb := redis.NewClient(&redis.Options{
250+
Addr: "localhost:6379",
251+
Password: "", // no password set
252+
DB: 0, // use default DB
253+
Protocol: 3, // specify 2 for RESP 2 or 3 for RESP 3
254+
})
144255
```
145256

146257
### Connecting via a redis url
@@ -167,6 +278,24 @@ func ExampleClient() *redis.Client {
167278

168279
```
169280

281+
### Instrument with OpenTelemetry
282+
283+
```go
284+
import (
285+
"github.com/redis/go-redis/v9"
286+
"github.com/redis/go-redis/extra/redisotel/v9"
287+
"errors"
288+
)
289+
290+
func main() {
291+
...
292+
rdb := redis.NewClient(&redis.Options{...})
293+
294+
if err := errors.Join(redisotel.InstrumentTracing(rdb), redisotel.InstrumentMetrics(rdb)); err != nil {
295+
log.Fatal(err)
296+
}
297+
```
298+
170299
171300
### Advanced Configuration
172301
@@ -215,9 +344,26 @@ val1 := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{})
215344
216345
In the Redis-Search module, **the default dialect is 2**. If needed, you can explicitly specify a different dialect using the appropriate configuration in your queries.
217346
218-
## Contributing
347+
**Important**: Be aware that the query dialect may impact the results returned. If needed, you can revert to a different dialect version by passing the desired dialect in the arguments of the command you want to execute.
348+
For example:
349+
```
350+
res2, err := rdb.FTSearchWithArgs(ctx,
351+
"idx:bicycle",
352+
"@pickup_zone:[CONTAINS $bike]",
353+
&redis.FTSearchOptions{
354+
Params: map[string]interface{}{
355+
"bike": "POINT(-0.1278 51.5074)",
356+
},
357+
DialectVersion: 3,
358+
},
359+
).Result()
360+
```
361+
You can find further details in the [query dialect documentation](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/dialects/).
219362
220-
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!
363+
## Contributing
364+
We welcome contributions to the go-redis library! If you have a bug fix, feature request, or improvement, please open an issue or pull request on GitHub.
365+
We appreciate your help in making go-redis better for everyone.
366+
If you are interested in contributing to the go-redis library, please check out our [contributing guidelines](CONTRIBUTING.md) for more information on how to get started.
221367
222368
## Look and feel
223369

0 commit comments

Comments
 (0)