Skip to content

Commit

Permalink
Use go-redis UniversalOptions/Client for simpler config
Browse files Browse the repository at this point in the history
This implicitly adds support for redis sentinel HA configuration
  • Loading branch information
andsens committed Mar 18, 2024
1 parent 38e7252 commit 0dd2cd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions auth_server/authn/tokendb_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

type RedisStoreConfig struct {
ClientOptions *redis.Options `yaml:"redis_options,omitempty"`
ClientOptions *redis.UniversalOptions `yaml:"redis_options,omitempty"`
ClusterOptions *redis.ClusterOptions `yaml:"redis_cluster_options,omitempty"`
TokenHashCost int `yaml:"token_hash_cost,omitempty"`
}
Expand All @@ -51,7 +51,7 @@ func NewRedisTokenDB(options *RedisStoreConfig) (TokenDB, error) {
}
client = redis.NewClusterClient(options.ClusterOptions)
} else {
client = redis.NewClient(options.ClientOptions)
client = redis.NewUniversalClient(options.ClientOptions)
}
tokenHashCost := options.TokenHashCost
if tokenHashCost <= 0 {
Expand Down
16 changes: 10 additions & 6 deletions examples/reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,13 @@ github_auth:
# or Redis,
redis_token_db:
redis_options:
# with a single instance,
addr: localhost:6379
redis_cluster_options:
# or in the cluster mode.
addrs: ["localhost:7000"]
# with a single instance,
addr: localhost:6379
# or in the cluster mode.
addrs: ["localhost:7000"]
# or in the failover mode with redis sentinel.
mastername: redis-ha
sentineladdrs: ["redis-sentinel:26379"]
# How long to wait when talking to GitHub servers. Optional.
http_timeout: "10s"
# How long to wait before revalidating the GitHub token. Optional.
Expand Down Expand Up @@ -221,9 +223,11 @@ gitlab_auth:
redis_options:
# with a single instance,
addr: localhost:6379
redis_cluster_options:
# or in the cluster mode.
addrs: ["localhost:7000"]
# or in the failover mode with redis sentinel.
mastername: redis-ha
sentineladdrs: ["redis-sentinel:26379"]
# How long to wait when talking to GitLab servers. Optional.
http_timeout: "10s"
# How long to wait before revalidating the Gitlab token. Optional.
Expand Down

0 comments on commit 0dd2cd7

Please sign in to comment.