forked from gomods/athens
-
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.
Adds redis sentinel support (gomods#1554)
* Adds redis sentinel support Fixes gomods#1553 * Fix redis-sentinel test hostnames * Fix redis master name again * Fix redis sentinel port in tests * Upgrade the redis client * Rmoeve accidental config change * Fix default config * Addresses review comments * Add documentation on single flight mechanisms * Fix spelling issues * Fix formatting Co-authored-by: Aaron Schlesinger <[email protected]>
- Loading branch information
Showing
12 changed files
with
262 additions
and
12 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
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
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,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) { | ||
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 | ||
} |
Oops, something went wrong.