memcached

package module
v0.38.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	testcontainers.Container
}

Container represents the Memcached container type used in the module

func Run

func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)

Run creates an instance of the Memcached container type

Example
// runMemcachedContainer {
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
}
// }

state, err := memcachedContainer.State(ctx)
if err != nil {
	log.Printf("failed to get container state: %s", err)
	return
}

fmt.Println(state.Running)
Output:

true
Example (Connect)
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
}

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

mc := memcache.New(hostPort)

err = mc.Set(&memcache.Item{Key: "foo", Value: []byte("my value")})
if err != nil {
	log.Printf("failed to set item: %s", err)
	return
}

it, err := mc.Get("foo")
if err != nil {
	log.Printf("failed to get item: %s", err)
	return
}

fmt.Println(string(it.Value))
Output:

my value

func (*Container) HostPort

func (c *Container) HostPort(ctx context.Context) (string, error)

HostPort returns the host and port of the Memcached container

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL