Skip to content
Snippets Groups Projects
Commit c0912081 authored by Lyuben Penkovski's avatar Lyuben Penkovski
Browse files

Add client support for Redis cluster

parent bd3054ba
No related branches found
No related tags found
No related merge requests found
Showing
with 58 additions and 295 deletions
......@@ -11,9 +11,9 @@ stages:
- deploy
include:
- project: '${HELPERS_PATH}'
file: '${HELPERS_FILE}'
- template: 'Workflows/Branch-Pipelines.gitlab-ci.yml'
- project: "${HELPERS_PATH}"
file: "${HELPERS_FILE}"
- template: "Workflows/Branch-Pipelines.gitlab-ci.yml"
lint:
image: golangci/golangci-lint:v1.50.1
......@@ -28,15 +28,16 @@ lint:
- cd /go/src/gitlab.com/${CI_PROJECT_PATH}
unit tests:
image: golang:1.19.3
image: golang:1.19.4
extends: .gotest
stage: test
tags:
- amd64-docker
before_script: []
coverage: '/total:\s+\(statements\)\s+(\d+.\d+\%)/'
govulncheck:
image: golang:1.19.3
image: golang:1.19.4
stage: test
tags:
- amd64-docker
......
......@@ -50,7 +50,7 @@ func main() {
logger.Info("start cache service", zap.String("version", Version), zap.String("goa", goa.Version()))
// create redis client
redis := redis.New(cfg.Redis.Addr, cfg.Redis.User, cfg.Redis.Pass, cfg.Redis.DB, cfg.Redis.TTL)
redis := redis.New(cfg.Redis.Addr, cfg.Redis.User, cfg.Redis.Pass, cfg.Redis.DB, cfg.Redis.TTL, cfg.Redis.Cluster)
// create event client
events, err := event.New(cfg.Nats.Addr, cfg.Nats.Subject)
......
module gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/cache
go 1.17
go 1.19
require (
github.com/cloudevents/sdk-go/protocol/nats/v2 v2.10.1
github.com/cloudevents/sdk-go/v2 v2.11.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-redis/redis/v9 v9.0.0-rc.2
github.com/google/uuid v1.3.0
github.com/kelseyhightower/envconfig v1.4.0
github.com/prometheus/client_golang v1.13.0
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib v1.1.1-0.20221006064046-cc9c0e9603bf
go.uber.org/zap v1.23.0
goa.design/goa/v3 v3.8.5
......@@ -56,8 +56,8 @@ require (
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
......
This diff is collapsed.
......@@ -2,28 +2,44 @@ package redis
import (
"context"
"strings"
"time"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v9"
"gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/golib/errors"
)
type Client struct {
rdb *redis.Client
rdb redis.Cmdable
defaultTTL time.Duration
}
func New(addr, user, pass string, db int, defaultTTL time.Duration) *Client {
rdb := redis.NewClient(&redis.Options{
Addr: addr,
Username: user,
Password: pass,
DB: db,
DialTimeout: 10 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
})
func New(addr, user, pass string, db int, defaultTTL time.Duration, cluster bool) *Client {
var rdb redis.Cmdable
if cluster {
nodes := strings.Split(addr, ";")
rdb = redis.NewClusterClient(&redis.ClusterOptions{
Addrs: nodes,
Username: user,
Password: pass,
RouteByLatency: true,
DialTimeout: 10 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
MaxRedirects: 10,
})
} else {
rdb = redis.NewClient(&redis.Options{
Addr: addr,
Username: user,
Password: pass,
DB: db,
DialTimeout: 10 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
})
}
return &Client{
rdb: rdb,
......
......@@ -21,11 +21,12 @@ type httpConfig struct {
}
type redisConfig struct {
Addr string `envconfig:"REDIS_ADDR" required:"true"`
User string `envconfig:"REDIS_USER" required:"true"`
Pass string `envconfig:"REDIS_PASS" required:"true"`
DB int `envconfig:"REDIS_DB" default:"0"`
TTL time.Duration `envconfig:"REDIS_EXPIRATION"` // no default expiration, keys are set to live forever
Addr string `envconfig:"REDIS_ADDR" required:"true"`
User string `envconfig:"REDIS_USER" required:"true"`
Pass string `envconfig:"REDIS_PASS" required:"true"`
DB int `envconfig:"REDIS_DB" default:"0"`
TTL time.Duration `envconfig:"REDIS_EXPIRATION"` // no default expiration, keys are set to live forever
Cluster bool `envconfig:"REDIS_CLUSTER" default:"false"`
}
type natsConfig struct {
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment