github.com/letsencrypt/boulder@v0.20251208.0/test/boulder-tools/flushredis/main.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 8 "github.com/letsencrypt/boulder/cmd" 9 blog "github.com/letsencrypt/boulder/log" 10 "github.com/letsencrypt/boulder/metrics" 11 bredis "github.com/letsencrypt/boulder/redis" 12 13 "github.com/redis/go-redis/v9" 14 ) 15 16 func main() { 17 rc := bredis.Config{ 18 Username: "boulder", 19 TLS: cmd.TLSConfig{ 20 CACertFile: "test/certs/ipki/minica.pem", 21 CertFile: "test/certs/ipki/localhost/cert.pem", 22 KeyFile: "test/certs/ipki/localhost/key.pem", 23 }, 24 Lookups: []cmd.ServiceDomain{ 25 { 26 Service: "redisratelimits", 27 Domain: "service.consul", 28 }, 29 }, 30 LookupDNSAuthority: "consul.service.consul", 31 } 32 rc.PasswordConfig = cmd.PasswordConfig{ 33 PasswordFile: "test/secrets/redis_password", 34 } 35 36 stats := metrics.NoopRegisterer 37 log := blog.NewMock() 38 ring, err := bredis.NewRingFromConfig(rc, stats, log) 39 if err != nil { 40 fmt.Printf("while constructing ring client: %v\n", err) 41 os.Exit(1) 42 } 43 44 err = ring.ForEachShard(context.Background(), func(ctx context.Context, shard *redis.Client) error { 45 cmd := shard.FlushAll(ctx) 46 _, err := cmd.Result() 47 if err != nil { 48 return err 49 } 50 return nil 51 }) 52 if err != nil { 53 fmt.Printf("while flushing redis shards: %v\n", err) 54 os.Exit(1) 55 } 56 }