Skip to content

Commit 6184ad5

Browse files
authored
Add MakeReadClient for creating a redis reader (letsencrypt#5814)
Add a function to create and return a read only redis client.
1 parent 5737007 commit 6184ad5

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

rocsp/config/rocsp_config.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,38 @@ func MakeClient(c *RedisConfig, clk clock.Clock) (*rocsp.WritingClient, error) {
103103
})
104104
return rocsp.NewWritingClient(rdb, timeout, clk), nil
105105
}
106+
107+
func MakeReadClient(c *RedisConfig, clk clock.Clock) (*rocsp.Client, error) {
108+
password, err := c.PasswordConfig.Pass()
109+
if err != nil {
110+
return nil, fmt.Errorf("loading password: %w", err)
111+
}
112+
113+
tlsConfig, err := c.TLS.Load()
114+
if err != nil {
115+
return nil, fmt.Errorf("loading TLS config: %w", err)
116+
}
117+
118+
timeout := c.Timeout.Duration
119+
120+
rdb := redis.NewClusterClient(&redis.ClusterOptions{
121+
Addrs: c.Addrs,
122+
Username: c.Username,
123+
Password: password,
124+
TLSConfig: tlsConfig,
125+
126+
MaxRetries: c.MaxRetries,
127+
MinRetryBackoff: c.MinRetryBackoff.Duration,
128+
MaxRetryBackoff: c.MaxRetryBackoff.Duration,
129+
DialTimeout: c.DialTimeout.Duration,
130+
ReadTimeout: c.ReadTimeout.Duration,
131+
132+
PoolSize: c.PoolSize,
133+
MinIdleConns: c.MinIdleConns,
134+
MaxConnAge: c.MaxConnAge.Duration,
135+
PoolTimeout: c.PoolTimeout.Duration,
136+
IdleTimeout: c.IdleTimeout.Duration,
137+
IdleCheckFrequency: c.IdleCheckFrequency.Duration,
138+
})
139+
return rocsp.NewClient(rdb, timeout, clk), nil
140+
}

rocsp/rocsp.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,14 @@ func MakeMetadataKey(serial string) string {
6464

6565
// Client represents a read-only Redis client.
6666
type Client struct {
67-
prefix string
6867
rdb *redis.ClusterClient
6968
timeout time.Duration
7069
clk clock.Clock
7170
}
7271

7372
// NewClient creates a Client. The timeout applies to all requests, though a shorter timeout can be
7473
// applied on a per-request basis using context.Context.
75-
// The prefix is used to simulate different Redis clusters for different purposes - for instance
76-
// integration testing and unittesting.
77-
func NewClient(rdb *redis.ClusterClient, prefix string, timeout time.Duration, clk clock.Clock) *Client {
74+
func NewClient(rdb *redis.ClusterClient, timeout time.Duration, clk clock.Clock) *Client {
7875
return &Client{
7976
rdb: rdb,
8077
timeout: timeout,

0 commit comments

Comments
 (0)