Skip to content

Commit ca15191

Browse files
authored
feat: add support for configuring Redis connection with username (#30)
* feat: add support for configuring Redis connection with username - Add `username` field to the `options` struct - Add `WithUsername` function to set the `username` option - Include `username` in the `NewWorker` function for Redis connection configuration Signed-off-by: appleboy <[email protected]> * ci: update Go version to 1.20 and adjust GitHub Actions accordingly - Remove support for Go 1.18 and 1.19 in GitHub Actions workflow - Update Go version in `go.mod` from 1.18 to 1.20 Signed-off-by: appleboy <[email protected]> --------- Signed-off-by: appleboy <[email protected]>
1 parent aba0014 commit ca15191

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
strategy:
2323
matrix:
2424
os: [ubuntu-latest]
25-
go: [1.18, 1.19, "1.20", 1.21, 1.22, 1.23]
25+
go: ["1.20", 1.21, 1.22, 1.23]
2626
include:
2727
- os: ubuntu-latest
2828
go-build: ~/.cache/go-build

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/golang-queue/redisdb
22

3-
go 1.18
3+
go 1.20
44

55
require (
66
github.com/golang-queue/queue v0.1.4-0.20221210024521-cb8720b0c721

options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type options struct {
1616
addr string
1717
db int
1818
connectionString string
19+
username string
1920
password string
2021
channelName string
2122
channelSize int
@@ -66,6 +67,13 @@ func WithChannelSize(size int) Option {
6667
}
6768
}
6869

70+
// WithUsername redis username
71+
func WithUsername(username string) Option {
72+
return func(w *options) {
73+
w.username = username
74+
}
75+
}
76+
6977
// WithPassword redis password
7078
func WithPassword(passwd string) Option {
7179
return func(w *options) {

redis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ func NewWorker(opts ...Option) *Worker {
4242

4343
options := &redis.Options{
4444
Addr: w.opts.addr,
45+
Username: w.opts.username,
4546
Password: w.opts.password,
4647
DB: w.opts.db,
4748
}
@@ -58,6 +59,7 @@ func NewWorker(opts ...Option) *Worker {
5859
if w.opts.cluster {
5960
w.rdb = redis.NewClusterClient(&redis.ClusterOptions{
6061
Addrs: strings.Split(w.opts.addr, ","),
62+
Username: w.opts.username,
6163
Password: w.opts.password,
6264
})
6365
}
@@ -66,6 +68,7 @@ func NewWorker(opts ...Option) *Worker {
6668
w.rdb = redis.NewFailoverClient(&redis.FailoverOptions{
6769
MasterName: w.opts.masterName,
6870
SentinelAddrs: strings.Split(w.opts.addr, ","),
71+
Username: w.opts.username,
6972
Password: w.opts.password,
7073
DB: w.opts.db,
7174
})

0 commit comments

Comments
 (0)