feat(redis): add suppport for credentials and TLS
By using `ParseURL` it is now possible to - Supply login credentials for the redis instance - Use an encrypted TLS connection by setting the scheme to `rediss://`
This commit is contained in:
parent
3d816053ec
commit
e0a88666af
1 changed files with 15 additions and 3 deletions
|
|
@ -2,6 +2,7 @@ package redisstream
|
|||
|
||||
import (
|
||||
"log"
|
||||
"regexp"
|
||||
|
||||
"github.com/go-redis/redis"
|
||||
|
||||
|
|
@ -14,9 +15,20 @@ func getRedisClient() *redis.Client {
|
|||
if redisClient != nil {
|
||||
return redisClient
|
||||
}
|
||||
redisClient = redis.NewClient(&redis.Options{
|
||||
Addr: env.String("REDIS_STRING"),
|
||||
})
|
||||
|
||||
connectionString := env.String("REDIS_STRING")
|
||||
|
||||
match, _ := regexp.MatchString("^[^:]+://", connectionString)
|
||||
if !match {
|
||||
connectionString = "redis://" + connectionString
|
||||
}
|
||||
|
||||
options, err := redis.ParseURL(connectionString)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
redisClient = redis.NewClient(options)
|
||||
if _, err := redisClient.Ping().Result(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue