memcachex v0.4.2 Memcache.Connection
This module provides low level API to connect and execute commands on a memcached server.
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
Functions
Closes the connection to the memcached server.
Example
iex> {:ok, pid} = Memcache.Connection.start_link()
iex> Memcache.Connection.close(pid)
{:ok}
execute(GenServer.server, atom, [binary], Keyword.t) :: Memcache.result
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 tofalse
Example
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"}
execute_quiet(GenServer.server, [{atom, [binary]} | {atom, [binary], Keyword.t}]) :: {:ok, [Memcache.result]} | {:error, atom}
Executes the list of quiet commands
Example
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"}]}
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 to11211
:backoff_initial
- (integer) initial backoff (in milliseconds) to be used in case of connection failure. Defaults to500
:backoff_max
- (integer) maximum allowed interval between two connection attempt. Defaults to30_000
:auth
- (tuple) only plain authentication method is supported. It is specified using the following format{:plain, "username", "password"}
. Defaults tonil
.
Example
{:ok, pid} = Memcache.Connection.start_link()