-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcli.go
43 lines (34 loc) · 861 Bytes
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import "context"
type Cli struct {
Ctr *Container
}
// CLI returns a new container running the Redis CLI connected to a redis Service.
func (r *Redis) Cli(
// The Redis server to connect to.
server *Service,
) (*Cli, error) {
ctr, err := r.Server()
if err != nil {
return nil, err
}
entrypointCmd := []string{"redis-cli", "-h", "redis"}
if r.Password != nil {
ctr = ctr.WithSecretVariable("REDISCLI_AUTH", r.Password)
}
ctr = ctr.
WithServiceBinding("redis", server).
WithEntrypoint(entrypointCmd)
return &Cli{
Ctr: ctr,
}, nil
}
func (c *Cli) Container() *Container {
return c.Ctr
}
func (c *Cli) Set(key, value string) *Container {
return c.Ctr.WithExec([]string{"SET", key, value})
}
func (c *Cli) Get(ctx context.Context, key string) (string, error) {
return c.Ctr.WithExec([]string{"GET", key}).Stdout(ctx)
}