Memcache.Connection (memcachex v0.5.5) View Source

This module provides low level API to connect and execute commands on a memcached server.

Link to this section Summary

Functions

Closes the connection to the memcached server.

Executes the command with the given args

Executes the list of quiet commands

Starts a connection to memcached server.

Link to this section Functions

Specs

close(GenServer.server()) :: {:ok}

Closes the connection to the memcached server.

Examples

iex> {:ok, pid} = Memcache.Connection.start_link()
iex> Memcache.Connection.close(pid)
{:ok}
Link to this function

execute(pid, command, args, options \\ [])

View Source

Specs

Executes the command with the given args

options

  • :cas - (boolean) returns the CAS value associated with the data. This value will be either in second or third position of the returned tuple depending on the command. Defaults to false

Examples

iex> {:ok, pid} = Memcache.Connection.start_link()
iex> {:ok} = Memcache.Connection.execute(pid, :SET, ["hello", "world"])
iex> {:ok, "world"} = Memcache.Connection.execute(pid, :GET, ["hello"])
{:ok, "world"}
Link to this function

execute_quiet(pid, commands)

View Source

Specs

execute_quiet(GenServer.server(), [
  {atom(), [binary()]} | {atom(), [binary()], Keyword.t()}
]) ::
  {:ok, [Memcache.result()]} | {:error, atom()}

Executes the list of quiet commands

Examples

iex> {:ok, pid} = Memcache.Connection.start_link()
iex> {:ok, [{:ok}, {:ok}]} = Memcache.Connection.execute_quiet(pid, [{:SETQ, ["1", "one"]}, {:SETQ, ["2", "two"]}])
iex> Memcache.Connection.execute_quiet(pid, [{:GETQ, ["1"]}, {:GETQ, ["2"]}])
{:ok, [{:ok, "one"}, {:ok, "two"}]}
Link to this function

start_link(connection_options \\ [], options \\ [])

View Source

Specs

start_link(Keyword.t(), Keyword.t()) :: GenServer.on_start()

Starts a connection to memcached server.

The actual TCP connection to the memcached server is established asynchronously after the start_link/2 returns.

This function accepts two option lists. The first one specifies the options to connect to the memcached server. The second option is passed directly to the underlying GenServer.start_link/3, so it can be used to create named process.

Memcachex automatically tries to reconnect in case of tcp connection failures. It starts with a :backoff_initial wait time and increases the wait time exponentially on each successive failures until it reaches the :backoff_max. After that, it waits for :backoff_max after each failure.

Connection Options

  • :hostname - (string) hostname of the memcached server. Defaults to "localhost"

  • :port - (integer) port on which the memcached server is listening. Defaults to 11211

  • :backoff_initial - (integer) initial backoff (in milliseconds) to be used in case of connection failure. Defaults to 500

  • :backoff_max - (integer) maximum allowed interval between two connection attempt. Defaults to 30_000

  • :connect_timeout - (integer) connection timeout (in milliseconds) at which to terminate the connection attempt in case of an unresponsive host. Defaults to :infinity

  • :auth - (tuple) only plain authentication method is supported. It is specified using the following format {:plain, "username", "password"}. Defaults to nil.

Examples

{:ok, pid} = Memcache.Connection.start_link()