-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from philips-software/feature/redis-db
Add support for Redis DB broker
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package hsdp | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cloudfoundry-community/gautocloud" | ||
"github.com/cloudfoundry-community/gautocloud/connectors" | ||
"github.com/go-redis/redis/v8" | ||
) | ||
|
||
type RedisCredentials struct { | ||
Hostname string `json:"hostname"` | ||
MasterName string `json:"master_name"` | ||
Password string `json:"password"` | ||
Port int `json:"port"` | ||
SentinelPort int `json:"sentinel_port"` | ||
} | ||
|
||
type RedisSchema RedisCredentials | ||
|
||
func init() { | ||
gautocloud.RegisterConnector(NewRedisConnector()) | ||
} | ||
|
||
type RedisConnector struct { | ||
} | ||
|
||
func (r RedisConnector) Id() string { | ||
return "hsdp:redis-db" | ||
} | ||
|
||
func (r RedisConnector) Name() string { | ||
return ".*redis-db.*" | ||
} | ||
|
||
func (r RedisConnector) Tags() []string { | ||
return []string{"Redis.*", "redis-db.*"} | ||
} | ||
|
||
func (r RedisConnector) Load(schema interface{}) (interface{}, error) { | ||
fSchema, ok := schema.(RedisSchema) | ||
if !ok { | ||
return nil, fmt.Errorf("no RedisSchema detected") | ||
} | ||
|
||
rdb := redis.NewFailoverClusterClient(&redis.FailoverOptions{ | ||
MasterName: fSchema.MasterName, | ||
SentinelAddrs: []string{fmt.Sprintf("%s:%d", fSchema.Hostname, fSchema.SentinelPort)}, | ||
SentinelPassword: fSchema.Password, | ||
Password: fSchema.Password, | ||
//RouteByLatency: true, | ||
//RouteRandomly: true, | ||
}) | ||
return rdb, nil | ||
} | ||
|
||
func (r RedisConnector) Schema() interface{} { | ||
return RedisSchema{} | ||
} | ||
|
||
func NewRedisConnector() connectors.Connector { | ||
return &RedisConnector{} | ||
} |