Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
use separate redis clients for storage and async engine (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
krancour authored and jeremyrickard committed Dec 29, 2017
1 parent 6a8a319 commit 7d717af
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
23 changes: 17 additions & 6 deletions cmd/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,33 @@ func main() {
},
).Info("Open Service Broker for Azure starting")

// Redis client
// Redis clients
redisConfig, err := getRedisConfig()
if err != nil {
log.Fatal(err)
}
redisOpts := &redis.Options{
storageRedisOpts := &redis.Options{
Addr: fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port),
Password: redisConfig.Password,
DB: redisConfig.DB,
DB: redisConfig.StorageDB,
MaxRetries: 5,
}
asyncRedisOpts := &redis.Options{
Addr: fmt.Sprintf("%s:%d", redisConfig.Host, redisConfig.Port),
Password: redisConfig.Password,
DB: redisConfig.AsyncDB,
MaxRetries: 5,
}
if redisConfig.EnableTLS {
redisOpts.TLSConfig = &tls.Config{
storageRedisOpts.TLSConfig = &tls.Config{
ServerName: redisConfig.Host,
}
asyncRedisOpts.TLSConfig = &tls.Config{
ServerName: redisConfig.Host,
}
}
redisClient := redis.NewClient(redisOpts)
storageRedisClient := redis.NewClient(storageRedisOpts)
asyncRedisClient := redis.NewClient(asyncRedisOpts)

// Crypto
cryptoConfig, err := getCryptoConfig()
Expand Down Expand Up @@ -106,7 +116,8 @@ func main() {

// Create broker
broker, err := broker.NewBroker(
redisClient,
storageRedisClient,
asyncRedisClient,
codec,
authenticator,
modules,
Expand Down
3 changes: 2 additions & 1 deletion cmd/broker/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ type redisConfig struct {
Host string `envconfig:"REDIS_HOST" required:"true"`
Port int `envconfig:"REDIS_PORT" default:"6379"`
Password string `envconfig:"REDIS_PASSWORD" default:""`
DB int `envconfig:"REDIS_DB" default:"0"`
StorageDB int `envconfig:"REDIS_STORAGE_DB" default:"0"`
AsyncDB int `envconfig:"REDIS_ASYNC_DB" default:"1"`
EnableTLS bool `envconfig:"REDIS_ENABLE_TLS" default:"false"`
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ type broker struct {

// NewBroker returns a new Broker
func NewBroker(
redisClient *redis.Client,
storageRedisClient *redis.Client,
asyncRedisClient *redis.Client,
codec crypto.Codec,
authenticator authenticator.Authenticator,
modules []service.Module,
Expand Down Expand Up @@ -89,8 +90,8 @@ func NewBroker(
}
catalog := service.NewCatalog(services)
b := &broker{
store: storage.NewStore(redisClient, catalog, codec),
asyncEngine: async.NewEngine(redisClient),
store: storage.NewStore(storageRedisClient, catalog, codec),
asyncEngine: async.NewEngine(asyncRedisClient),
catalog: catalog,
}

Expand Down
1 change: 1 addition & 0 deletions pkg/broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func TestBrokerStartBlocksUntilContextCanceled(t *testing.T) {

func getTestBroker() (*broker, error) {
b, err := NewBroker(
nil,
nil,
nil,
always.NewAuthenticator(),
Expand Down

0 comments on commit 7d717af

Please sign in to comment.