-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Support for Redis Cluster Client #46
Changes from 7 commits
35a5986
058ffbd
d48ee01
ae4beb6
82d18aa
0c09792
5694768
cab23fc
9b16d4e
ba543b3
5548567
07846f3
d2cb15e
7ca209a
63637e4
187f1ce
dad207a
1515ffd
07334a1
1860136
f693bb1
57e99c1
0c6185d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Build configuration | ||
|
||
version = 0.6.0 | ||
version = 0.6.1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ func (listener *EventsListener) ListenForMessages() { | |
fmt.Sprintf("configuration [%s] could not be found", fsm.ConfigId))) | ||
continue | ||
} | ||
previousState := fsm.State | ||
cfgFsm := ConfiguredStateMachine{ | ||
Config: cfg, | ||
FSM: fsm, | ||
|
@@ -101,8 +102,8 @@ func (listener *EventsListener) ListenForMessages() { | |
request.GetEvent().GetTransition().GetEvent(), err))) | ||
continue | ||
} | ||
listener.logger.Info("Event `%s` transitioned FSM [%s] to state `%s` - updating store", | ||
request.Event.Transition.Event, smId, fsm.State) | ||
listener.logger.Info("Event `%s` transitioned FSM [%s] to state `%s` from state `%s` - updating store", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated |
||
request.Event.Transition.Event, smId, fsm.State, previousState) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we add a log line before we try to "SendEvent" ? It seems like it can fail there and we wouldn't have the IDs logged (SM ID, event ID, previous state) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, adding as a debug entry
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not only we capture the error if |
||
err := listener.store.PutStateMachine(smId, fsm) | ||
if err != nil { | ||
listener.PostNotificationAndReportOutcome(makeResponse(&request, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,7 @@ const ( | |
|
||
type RedisStore struct { | ||
logger *slf4go.Log | ||
client *redis.Client | ||
client redis.Cmdable | ||
Timeout time.Duration | ||
MaxRetries int | ||
} | ||
|
@@ -141,42 +141,36 @@ func (csm *RedisStore) GetTimeout() time.Duration { | |
} | ||
|
||
func NewRedisStoreWithDefaults(address string) StoreManager { | ||
return NewRedisStore(address, DefaultRedisDb, DefaultTimeout, DefaultMaxRetries) | ||
return NewRedisStore(address, false, DefaultRedisDb, DefaultTimeout, DefaultMaxRetries) | ||
} | ||
|
||
func NewRedisStore(address string, db int, timeout time.Duration, maxRetries int) StoreManager { | ||
|
||
func NewRedisStore(address string, isCluster bool, db int, timeout time.Duration, maxRetries int) StoreManager { | ||
logger := slf4go.NewLog(fmt.Sprintf("redis://%s/%d", address, db)) | ||
|
||
var tlsConfig *tls.Config | ||
var client redis.Cmdable | ||
|
||
if os.Getenv("REDIS_TLS") != "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is already in
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, see here it's been merged in |
||
logger.Info("Using TLS for Redis connection") | ||
tlsConfig = &tls.Config{MinVersion: tls.VersionTLS12} | ||
} | ||
return &RedisStore{ | ||
logger: logger, | ||
client: redis.NewClient(&redis.Options{ | ||
|
||
if isCluster { | ||
client = redis.NewClusterClient(&redis.ClusterOptions{ | ||
TLSConfig: tlsConfig, | ||
Addrs: strings.Split(address, ","), | ||
}) | ||
} else { | ||
client = redis.NewClient(&redis.Options{ | ||
TLSConfig: tlsConfig, | ||
Addr: address, | ||
DB: db, // 0 means default DB | ||
}), | ||
Timeout: timeout, | ||
MaxRetries: maxRetries, | ||
}) | ||
} | ||
} | ||
|
||
// FIXME: the "constructor" functions are very similar, the creation pattern will need to be | ||
// refactored to avoid code duplication. | ||
|
||
func NewRedisStoreWithCreds(address string, db int, timeout time.Duration, maxRetries int, | ||
username string, password string) StoreManager { | ||
return &RedisStore{ | ||
logger: slf4go.NewLog(fmt.Sprintf("redis:%s", address)), | ||
client: redis.NewClient(&redis.Options{ | ||
Addr: address, | ||
Username: username, | ||
Password: password, | ||
DB: db, | ||
}), | ||
logger: slf4go.NewLog(fmt.Sprintf("redis://%s/%d", address, db)), | ||
client: client, | ||
Timeout: timeout, | ||
MaxRetries: maxRetries, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it apply on any Redis deployment in cluster mode? or just Elasticache? If any, then we can remove the "Elasticache" part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated