Skip to content

Memcached

Not available until the next release main

Introduction

The Testcontainers module for Memcached.

Adding this module to your project dependencies

Please run the following command to add the Memcached module to your Go dependencies:

go get github.com/testcontainers/testcontainers-go/modules/memcached

Usage example

ctx := context.Background()

memcachedContainer, err := memcached.Run(ctx, "memcached:1.6-alpine")
defer func() {
    if err := testcontainers.TerminateContainer(memcachedContainer); err != nil {
        log.Printf("failed to terminate container: %s", err)
    }
}()
if err != nil {
    log.Printf("failed to start container: %s", err)
    return
}

Module Reference

Run function

  • Not available until the next release main

The Memcached module exposes one entrypoint function to create the Memcached container, and this function receives three parameters:

func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
  • context.Context, the Go context.
  • string, the Docker image to use.
  • testcontainers.ContainerCustomizer, a variadic argument for passing options.

Image

Use the second argument in the Run function to set a valid Docker image. In example: Run(context.Background(), "memcached:1.6-alpine").

Container Options

When starting the Memcached container, you can pass options in a variadic way to configure it.

The following options are exposed by the testcontainers package.

Basic Options

Lifecycle Options

Files & Mounts Options

Build Options

Logging Options

Image Options

Networking Options

Advanced Options

Experimental Options

Container Methods

The Memcached container exposes the following methods:

HostPort

  • Not available until the next release main

The HostPort method returns the host and port of the Memcached container, in the format host:port. Use this method to connect to the Memcached container from your application.

hostPort, err := memcachedContainer.HostPort(ctx)
if err != nil {
    log.Printf("failed to get host and port: %s", err)
    return
}