Use go get
to install the latest version of the library.
go get -u github.com/bitcoin-sv/testcontainers-redis-go@latest
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
redis_db "github.com/redis/go-redis/v9"
redisTest "github.com/bitcoin-sv/testcontainers-redis-go"
)
func TestRedis(t *testing.T) {
redisClient := setupRedis(t)
// your code here
}
func setupRedis(t *testing.T) *redis_db.Client {
ctx := context.Background()
container, err := redisTest.RunContainer(ctx)
require.NoError(t, err)
t.Cleanup(func() {
err := container.Terminate(ctx)
require.NoError(t, err)
})
host, err := container.Host(ctx)
require.NoError(t, err)
port, err := container.ServicePort(ctx)
require.NoError(t, err)
client, err := redis_db.NewClient(&redis_db.Options{
Addr: fmt.Sprintf("%s:%d", host, port),
})
require.NoError(t, err)
return client
}