memcached

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package memcached contains an implementation of the `gokv.Store` interface for Memcached.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{
	Addresses:    []string{"localhost:11211"},
	Timeout:      &defaultTimeout,
	MaxIdleConns: 100,
	Codec:        encoding.JSON,
}

DefaultOptions is an Options object with default values. Addresses: "localhost:11211", Timeout: 200 milliseconds, MaxIdleConns: 100, Codec: encoding.JSON

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a gokv.Store implementation for Memcached.

func NewClient

func NewClient(options Options) (Client, error)

NewClient creates a new Memcached client.

func (Client) Close

func (c Client) Close() error

Close closes the client. In the Memcached implementation this doesn't have any effect.

func (Client) Delete

func (c Client) Delete(k string) error

Delete deletes the stored value for the given key. The key must not be longer than 250 bytes (this is a restriction of Memcached). Deleting a non-existing key-value pair does NOT lead to an error. The key must not be "".

func (Client) Get

func (c Client) Get(k string, v any) (found bool, err error)

Get retrieves the stored value for the given key. The key must not be longer than 250 bytes (this is a restriction of Memcached). You need to pass a pointer to the value, so in case of a struct the automatic unmarshalling can populate the fields of the object that v points to with the values of the retrieved object's values. If no value is found it returns (false, nil). The key must not be "" and the pointer must not be nil.

func (Client) Set

func (c Client) Set(k string, v any) error

Set stores the given value for the given key. The key must not be longer than 250 bytes (this is a restriction of Memcached). Values are automatically marshalled to JSON or gob (depending on the configuration). The key must not be "" and the value must not be nil.

type Options

type Options struct {
	// Addresses of all Memcached servers, including their port.
	// If a server is listed multiple times it gets a proportional amount of weight.
	// Optional ("localhost:11211" by default).
	Addresses []string
	// Timeout for requests.
	// The gomemcache package uses a default of 100 milliseconds,
	// which seems ok for the use of a caching server, but too low for the use of an (albeit ephemeral) key-value storage.
	// Optional (200 milliseconds by default).
	Timeout *time.Duration
	// Maximum number of idle connections per Memcached server.
	// Default max connections on the server are 1024, so 100 from one client should be fine.
	// The gomemcache package uses a default of 2, which seems to be too low regarding its description:
	// "This should be set to a number higher than your peak parallel requests".
	// 0 will lead to the default value being used.
	// Optional (100 by default).
	MaxIdleConns int
	// Encoding format.
	// Optional (encoding.JSON by default).
	Codec encoding.Codec
}

Options are the options for the Memcached client.

Jump to

Keyboard shortcuts

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