-
Notifications
You must be signed in to change notification settings - Fork 535
Adds redis sentinel support #1554
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
Changes from all commits
727ba3f
815ad26
e5a4f77
b65258a
8791b2e
fc5e66c
44431c0
77a3c61
290e97b
85926fd
647d0d1
770a6e6
cdbdad9
eea12c4
ea26fd6
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package stash | ||
|
|
||
| import ( | ||
| "github.com/go-redis/redis/v7" | ||
| "github.com/gomods/athens/pkg/errors" | ||
| "github.com/gomods/athens/pkg/storage" | ||
| ) | ||
|
|
||
| // WithRedisSentinelLock returns a distributed singleflight | ||
| // with a redis cluster that utilizes sentinel for quorum and failover | ||
| func WithRedisSentinelLock(endpoints []string, master, password string, checker storage.Checker) (Wrapper, error) { | ||
|
Collaborator
Author
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 could alternatively be compacted into
Member
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. I like that you've separated sentinel from redis itself. sentinel is treated differently enough in the redis docs that I think we should treat it differently here from a docs and code perspective. |
||
| const op errors.Op = "stash.WithRedisSentinelLock" | ||
| // The redis client constructor does not return an error when no endpoints | ||
| // are provided, so we check for ourselves. | ||
| if len(endpoints) == 0 { | ||
| return nil, errors.E(op, "no endpoints specified") | ||
| } | ||
| client := redis.NewFailoverClient(&redis.FailoverOptions{ | ||
| MasterName: master, | ||
| SentinelAddrs: endpoints, | ||
| SentinelPassword: password, | ||
| }) | ||
| _, err := client.Ping().Result() | ||
| if err != nil { | ||
| return nil, errors.E(op, err) | ||
| } | ||
| return func(s Stasher) Stasher { | ||
| return &redisLock{client, s, checker} | ||
| }, nil | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.