Skip to content

Commit 6ca7f75

Browse files
authored
feat(redis): allow passing in redis.UniversalClient
1 parent 43f0db6 commit 6ca7f75

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

consumer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ type ConsumerOptions struct {
5353
// Concurrency dictates how many goroutines to spawn to handle the messages.
5454
Concurrency int
5555
// RedisClient supersedes the RedisOptions field, and allows you to inject
56-
// an already-made *redis.Client for use in the consumer.
57-
RedisClient *redis.Client
56+
// an already-made Redis Client for use in the consumer. This may be either
57+
// the standard client or a cluster client.
58+
RedisClient redis.UniversalClient
5859
// RedisOptions allows you to configure the underlying Redis connection.
5960
// More info here:
6061
// https://pkg.go.dev/github.com/go-redis/redis/v7?tab=doc#Options.
@@ -74,7 +75,7 @@ type Consumer struct {
7475
Errors chan error
7576

7677
options *ConsumerOptions
77-
redis *redis.Client
78+
redis redis.UniversalClient
7879
consumers map[string]registeredConsumer
7980
streams []string
8081
queue chan *Message
@@ -121,7 +122,7 @@ func NewConsumerWithOptions(options *ConsumerOptions) (*Consumer, error) {
121122
options.ReclaimInterval = 1 * time.Second
122123
}
123124

124-
var r *redis.Client
125+
var r redis.UniversalClient
125126

126127
if options.RedisClient != nil {
127128
r = options.RedisClient

producer.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ type ProducerOptions struct {
2020
// manner. More info here: https://redis.io/commands/xadd#capped-streams.
2121
ApproximateMaxLength bool
2222
// RedisClient supersedes the RedisOptions field, and allows you to inject
23-
// an already-made *redis.Client for use in the consumer.
24-
RedisClient *redis.Client
23+
// an already-made Redis Client for use in the consumer. This may be either
24+
// the standard client or a cluster client.
25+
RedisClient redis.UniversalClient
2526
// RedisOptions allows you to configure the underlying Redis connection.
2627
// More info here:
2728
// https://pkg.go.dev/github.com/go-redis/redis/v7?tab=doc#Options.
@@ -34,7 +35,7 @@ type ProducerOptions struct {
3435
// processed later by a Consumer.
3536
type Producer struct {
3637
options *ProducerOptions
37-
redis *redis.Client
38+
redis redis.UniversalClient
3839
}
3940

4041
var defaultProducerOptions = &ProducerOptions{
@@ -51,7 +52,7 @@ func NewProducer() (*Producer, error) {
5152

5253
// NewProducerWithOptions creates a Producer using custom ProducerOptions.
5354
func NewProducerWithOptions(options *ProducerOptions) (*Producer, error) {
54-
var r *redis.Client
55+
var r redis.UniversalClient
5556

5657
if options.RedisClient != nil {
5758
r = options.RedisClient

redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func newRedisClient(options *RedisOptions) *redis.Client {
2929
// offers the functionality we need. Specifically, it also that it can connect
3030
// to the actual instance and that the instance supports Redis streams (i.e.
3131
// it's at least v5).
32-
func redisPreflightChecks(client *redis.Client) error {
32+
func redisPreflightChecks(client redis.UniversalClient) error {
3333
info, err := client.Info("server").Result()
3434
if err != nil {
3535
return err

0 commit comments

Comments
 (0)