Skip to content

Commit 573b047

Browse files
committed
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]>
1 parent aba0014 commit 573b047

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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)