redis.go 522 B

12345678910111213141516171819202122
  1. package adapter
  2. import (
  3. "context"
  4. "fmt"
  5. redis "github.com/go-redis/redis/v8"
  6. "github.com/porter-dev/porter/api/server/shared/config/env"
  7. )
  8. // NewRedisClient returns a new redis client instance
  9. func NewRedisClient(conf *env.RedisConf) (*redis.Client, error) {
  10. client := redis.NewClient(&redis.Options{
  11. Addr: fmt.Sprintf("%s:%s", conf.Host, conf.Port),
  12. Username: conf.Username,
  13. Password: conf.Password,
  14. DB: conf.DB,
  15. })
  16. _, err := client.Ping(context.Background()).Result()
  17. return client, err
  18. }