@@ -17,36 +17,39 @@ var redisVersionRE = regexp.MustCompile(`redis_version:(.+)`)
1717type RedisOptions = redis.Options
1818
1919// newRedisClient creates a new Redis client with the given options. If options
20- // is nil, it will use default options. In addition to creating the client, it
21- // also ensures that it can connect to the actual instance and that the instance
22- // supports Redis streams (i.e. it's at least v5).
23- func newRedisClient (options * RedisOptions ) (* redis.Client , error ) {
20+ // is nil, it will use default options.
21+ func newRedisClient (options * RedisOptions ) * redis.Client {
2422 if options == nil {
2523 options = & RedisOptions {}
2624 }
27- client := redis .NewClient (options )
25+ return redis .NewClient (options )
26+ }
2827
29- // make sure Redis supports streams (i.e. is at least v5)
28+ // redisPreflightChecks makes sure the Redis instance backing the *redis.Client
29+ // offers the functionality we need. Specifically, it also that it can connect
30+ // to the actual instance and that the instance supports Redis streams (i.e.
31+ // it's at least v5).
32+ func redisPreflightChecks (client * redis.Client ) error {
3033 info , err := client .Info ("server" ).Result ()
3134 if err != nil {
32- return nil , err
35+ return err
3336 }
3437
3538 match := redisVersionRE .FindAllStringSubmatch (info , - 1 )
3639 if len (match ) < 1 {
37- return nil , fmt .Errorf ("could not extract redis version" )
40+ return fmt .Errorf ("could not extract redis version" )
3841 }
3942 version := strings .TrimSpace (match [0 ][1 ])
4043 parts := strings .Split (version , "." )
4144 major , err := strconv .Atoi (parts [0 ])
4245 if err != nil {
43- return nil , err
46+ return err
4447 }
4548 if major < 5 {
46- return nil , fmt .Errorf ("redis streams are not supported in version %q" , version )
49+ return fmt .Errorf ("redis streams are not supported in version %q" , version )
4750 }
4851
49- return client , nil
52+ return nil
5053}
5154
5255// incrementMessageID takes in a message ID (e.g. 1564886140363-0) and
0 commit comments