Skip to content

Commit

Permalink
feat: add support for configuring Redis connection with username (#30)
Browse files Browse the repository at this point in the history
* 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 <appleboy.tw@gmail.com>

* 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 <appleboy.tw@gmail.com>

---------

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy authored Jan 5, 2025
1 parent aba0014 commit ca15191
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
go: [1.18, 1.19, "1.20", 1.21, 1.22, 1.23]
go: ["1.20", 1.21, 1.22, 1.23]
include:
- os: ubuntu-latest
go-build: ~/.cache/go-build
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/golang-queue/redisdb

go 1.18
go 1.20

require (
github.com/golang-queue/queue v0.1.4-0.20221210024521-cb8720b0c721
Expand Down
8 changes: 8 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type options struct {
addr string
db int
connectionString string
username string
password string
channelName string
channelSize int
Expand Down Expand Up @@ -66,6 +67,13 @@ func WithChannelSize(size int) Option {
}
}

// WithUsername redis username
func WithUsername(username string) Option {
return func(w *options) {
w.username = username
}
}

// WithPassword redis password
func WithPassword(passwd string) Option {
return func(w *options) {
Expand Down
3 changes: 3 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewWorker(opts ...Option) *Worker {

options := &redis.Options{
Addr: w.opts.addr,
Username: w.opts.username,
Password: w.opts.password,
DB: w.opts.db,
}
Expand All @@ -58,6 +59,7 @@ func NewWorker(opts ...Option) *Worker {
if w.opts.cluster {
w.rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: strings.Split(w.opts.addr, ","),
Username: w.opts.username,
Password: w.opts.password,
})
}
Expand All @@ -66,6 +68,7 @@ func NewWorker(opts ...Option) *Worker {
w.rdb = redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: w.opts.masterName,
SentinelAddrs: strings.Split(w.opts.addr, ","),
Username: w.opts.username,
Password: w.opts.password,
DB: w.opts.db,
})
Expand Down

0 comments on commit ca15191

Please sign in to comment.