Skip to content

Commit 74b703f

Browse files
committed
feat: add support for setting and using username in Redis connections
- Add `username` field to the `options` struct - Add `WithUsername` function to set the `username` in options - Include `Username` in Redis connection options in `NewWorker` function Signed-off-by: appleboy <[email protected]>
1 parent 488a745 commit 74b703f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

options.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type options struct {
1717
addr string
1818
db int
1919
connectionString string
20+
username string
2021
password string
2122
streamName string
2223
cluster bool
@@ -84,6 +85,14 @@ func WithConsumer(name string) Option {
8485
}
8586
}
8687

88+
// WithUsername redis username
89+
// This is only used for redis cluster
90+
func WithUsername(username string) Option {
91+
return func(w *options) {
92+
w.username = username
93+
}
94+
}
95+
8796
// WithPassword redis password
8897
func WithPassword(passwd string) Option {
8998
return func(w *options) {

redis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ func NewWorker(opts ...Option) *Worker {
5151
if w.opts.cluster {
5252
w.rdb = redis.NewClusterClient(&redis.ClusterOptions{
5353
Addrs: strings.Split(w.opts.addr, ","),
54+
Username: w.opts.username,
5455
Password: w.opts.password,
5556
})
5657
} else {
5758
options := &redis.Options{
5859
Addr: w.opts.addr,
60+
Username: w.opts.username,
5961
Password: w.opts.password,
6062
DB: w.opts.db,
6163
}

0 commit comments

Comments
 (0)