Skip to content

Commit 71f87e4

Browse files
committed
refactor: refactor comments in redis.go file
- Remove `deadcode` and `depguard` linters from `.golangci.yml` - Add `varcheck` linter to `.golangci.yml` - Update comments in `redis.go` file: - Remove comment `// NewWorker for struc` - Add comment explaining `NewWorker` function and its responsibilities - Update comment explaining the initialization of Redis client in `NewWorker` function - Update comment explaining the condition for initializing Redis client in `NewWorker` function - Update comment explaining the initialization of Redis client with sentinel in `NewWorker` function - Update comment explaining the condition for initializing Redis client with sentinel in `NewWorker` function - Remove unnecessary code for initializing Redis client in `NewWorker` function Signed-off-by: Bo-Yi Wu <[email protected]>
1 parent 5b04ecc commit 71f87e4

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

.golangci.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ linters:
33
disable-all: true
44
fast: false
55
enable:
6-
- deadcode
7-
- depguard
86
- dogsled
97
- dupl
108
- errcheck
@@ -30,7 +28,6 @@ linters:
3028
- typecheck
3129
- unconvert
3230
- unused
33-
- varcheck
3431
- whitespace
3532
- gofumpt
3633

redis.go

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,41 +29,46 @@ type Worker struct {
2929
opts options
3030
}
3131

32-
// NewWorker for struc
32+
// NewWorker creates a new Worker instance with the provided options.
33+
// It initializes a Redis client based on the options and establishes a connection to the Redis server.
34+
// The Worker is responsible for subscribing to a Redis channel and receiving messages from it.
35+
// It returns the created Worker instance.
3336
func NewWorker(opts ...Option) *Worker {
3437
var err error
3538
w := &Worker{
3639
opts: newOptions(opts...),
3740
stop: make(chan struct{}),
3841
}
3942

43+
options := &redis.Options{
44+
Addr: w.opts.addr,
45+
Password: w.opts.password,
46+
DB: w.opts.db,
47+
}
48+
w.rdb = redis.NewClient(options)
49+
4050
if w.opts.connectionString != "" {
4151
options, err := redis.ParseURL(w.opts.connectionString)
4252
if err != nil {
4353
w.opts.logger.Fatal(err)
4454
}
4555
w.rdb = redis.NewClient(options)
46-
} else if w.opts.addr != "" {
47-
if w.opts.cluster {
48-
w.rdb = redis.NewClusterClient(&redis.ClusterOptions{
49-
Addrs: strings.Split(w.opts.addr, ","),
50-
Password: w.opts.password,
51-
})
52-
} else if w.opts.sentinel {
53-
w.rdb = redis.NewFailoverClient(&redis.FailoverOptions{
54-
MasterName: w.opts.masterName,
55-
SentinelAddrs: strings.Split(w.opts.addr, ","),
56-
Password: w.opts.password,
57-
DB: w.opts.db,
58-
})
59-
} else {
60-
options := &redis.Options{
61-
Addr: w.opts.addr,
62-
Password: w.opts.password,
63-
DB: w.opts.db,
64-
}
65-
w.rdb = redis.NewClient(options)
66-
}
56+
}
57+
58+
if w.opts.cluster {
59+
w.rdb = redis.NewClusterClient(&redis.ClusterOptions{
60+
Addrs: strings.Split(w.opts.addr, ","),
61+
Password: w.opts.password,
62+
})
63+
}
64+
65+
if w.opts.sentinel {
66+
w.rdb = redis.NewFailoverClient(&redis.FailoverOptions{
67+
MasterName: w.opts.masterName,
68+
SentinelAddrs: strings.Split(w.opts.addr, ","),
69+
Password: w.opts.password,
70+
DB: w.opts.db,
71+
})
6772
}
6873

6974
_, err = w.rdb.Ping(context.Background()).Result()

0 commit comments

Comments
 (0)