Module eredis

Data Types

<a name="type-client">client()</a>

<code>client() = pid() | atom() | {atom(), atom()} | {global, term()} | {via, atom(), term()}</code>

<a name="type-host">host()</a>

<code>host() = string() | {local, string()}</code>

<a name="type-option">option()</a>

<code>option() = {host, string() | {local, string()}} | {port, <a href="inet.md#type-port_number">inet:port_number()</a>} | {database, integer() | string()} | {password, string()} | {reconnect_sleep, <a href="#type-reconnect_sleep">reconnect_sleep()</a>} | {connect_timeout, integer()} | {socket_options, list()} | {tls, [<a href="ssl.md#type-tls_client_option">ssl:tls_client_option()</a>]}</code>

<a name="type-options">options()</a>

<code>options() = [<a href="#type-option">option()</a>]</code>

<a name="type-pipeline">pipeline()</a>

<code>pipeline() = [iolist()]</code>

<a name="type-reconnect_sleep">reconnect_sleep()</a>

<code>reconnect_sleep() = no_reconnect | integer()</code>

<a name="type-return_value">return_value()</a>

<code>return_value() = undefined | binary() | [binary() | nonempty_list()]</code>

Function Index

<tr><td valign="top"><a href="#q-2">q/2</a></td><td> Executes the given command in the specified connection.</td></tr><tr><td valign="top"><a href="#q-3">q/3</a></td><td>Like q/2 with a custom timeout.</td></tr><tr><td valign="top"><a href="#q_async-2">q_async/2</a></td><td>Executes the command, and sends a message to the calling process with theresponse (with either error or success).</td></tr><tr><td valign="top"><a href="#q_async-3">q_async/3</a></td><td>Executes the command, and sends a message to <code>Pid</code> with the response(with either or success).</td></tr><tr><td valign="top"><a href="#q_noreply-2">q_noreply/2</a></td><td>Executes the command but does not wait for a response and ignores anyerrors.</td></tr><tr><td valign="top"><a href="#qp-2">qp/2</a></td><td> Executes the given pipeline (list of commands) in thespecified connection.</td></tr><tr><td valign="top"><a href="#qp-3">qp/3</a></td><td>Like qp/2 with a custom timeout.</td></tr><tr><td valign="top"><a href="#start_link-0">start_link/0</a></td><td>Connect with default options.</td></tr><tr><td valign="top"><a href="#start_link-1">start_link/1</a></td><td>Connect with the given options.</td></tr><tr><td valign="top"><a href="#start_link-2">start_link/2</a></td><td>Connect to the given host and port.</td></tr><tr><td valign="top"><a href="#start_link-3">start_link/3</a></td><td>(<em>Deprecated</em>.) </td></tr><tr><td valign="top"><a href="#start_link-4">start_link/4</a></td><td>(<em>Deprecated</em>.) </td></tr><tr><td valign="top"><a href="#start_link-5">start_link/5</a></td><td>(<em>Deprecated</em>.) </td></tr><tr><td valign="top"><a href="#start_link-6">start_link/6</a></td><td>(<em>Deprecated</em>.) </td></tr><tr><td valign="top"><a href="#start_link-7">start_link/7</a></td><td>(<em>Deprecated</em>.) </td></tr><tr><td valign="top"><a href="#stop-1">stop/1</a></td><td>Closes the connection and stops the client.</td></tr>

Function Details

q/2

<code>q(Client::<a href="#type-client">client()</a>, Command::[any()]) -&gt; {ok, <a href="#type-return_value">return_value()</a>} | {error, Reason::binary() | no_connection}</code>


Executes the given command in the specified connection. The command must be a valid Redis command and may contain arbitrary data which will be converted to binaries. The returned values will always be binaries.

q/3

<code>q(Client::<a href="#type-client">client()</a>, Command::[any()], Timeout::integer()) -&gt; {ok, <a href="#type-return_value">return_value()</a>} | {error, Reason::binary() | no_connection}</code>


Like q/2 with a custom timeout.

q_async/2

<code>q_async(Client::<a href="#type-client">client()</a>, Command::[any()]) -&gt; ok</code>


Executes the command, and sends a message to the calling process with the response (with either error or success). Message is of the form {response, Reply}, where Reply is the reply expected from q/2.

q_async/3

<code>q_async(Client::<a href="#type-client">client()</a>, Command::[any()], Pid::pid() | atom()) -&gt; ok</code>


Executes the command, and sends a message to Pid with the response (with either or success).

See also: q_async/2.

q_noreply/2

<code>q_noreply(Client::<a href="#type-client">client()</a>, Command::[any()]) -&gt; ok</code>


Executes the command but does not wait for a response and ignores any errors.

See also: q/2.

qp/2

<code>qp(Client::<a href="#type-client">client()</a>, Pipeline::<a href="#type-pipeline">pipeline()</a>) -&gt; [{ok, <a href="#type-return_value">return_value()</a>} | {error, Reason::binary()}] | {error, no_connection}</code>


Executes the given pipeline (list of commands) in the specified connection. The commands must be valid Redis commands and may contain arbitrary data which will be converted to binaries. The values returned by each command in the pipeline are returned in a list.

qp/3

<code>qp(Client::<a href="#type-client">client()</a>, Pipeline::<a href="#type-pipeline">pipeline()</a>, Timeout::integer()) -&gt; [{ok, <a href="#type-return_value">return_value()</a>} | {error, Reason::binary()}] | {error, no_connection}</code>


Like qp/2 with a custom timeout.

<code>start_link() -&gt; {ok, Pid::pid()} | {error, Reason::term()}</code>


Equivalent to start_link([]).

Connect with default options.

<code>start_link(Options::<a href="#type-options">options()</a>) -&gt; {ok, pid()} | {error, Reason::term()}</code>


Options:

<code>{host, Host}</code>
DNS name or IP address as string; or unix domain socket as <code>{local, Path}</code> (available in OTP 19+); default <code>"127.0.0.1"</code>
<code>{port, Port}</code>
Integer, default is 6379
<code>{database, Database}</code>
Integer (or string containing a number); 0 for default database
<code>{password, Password}</code>
String or empty string for no password; default: <code>""</code> i.e. no password
<code>{reconnect_sleep, ReconnectSleep}</code>
Integer of milliseconds to sleep between reconnect attempts; default: 100
<code>{connect_timeout, Timeout}</code>
Timeout value in milliseconds to use when connecting to Redis; default: 5000
<code>{socket_options, SockOpts}</code>
List of<a href="https://erlang.org/doc/man/gen_tcp.md">gen_tcp options</a> used when connecting the socket; default is <code>?SOCKET_OPTS</code>
<code>{tls, TlsOpts}</code>
Enabling TLS and a list of<a href="https://erlang.org/doc/man/ssl.md">ssl options</a>; used when establishing a TLS connection; default is off


Connect with the given options.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>) -&gt; {ok, Pid::pid()} | {error, Reason::term()}</code>


Equivalent to start_link([{host, Host}, {port, Port}]).

Connect to the given host and port.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>, OptionsOrDatabase) -&gt; {ok, Pid::pid()} | {error, Reason::term()}</code>
    <li><code>OptionsOrDatabase = <a href="#type-options">options()</a> | string()</code></li>

This function is deprecated: Use start_link/1 instead.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>, Database::string(), Password::string()) -&gt; {ok, pid()} | {error, term()}</code>


This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>, Database::string(), Password::string(), ReconnectSleep::<a href="#type-reconnect_sleep">reconnect_sleep()</a>) -&gt; {ok, pid()} | {error, term()}</code>


This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>, Database::string(), Password::string(), ReconnectSleep::<a href="#type-reconnect_sleep">reconnect_sleep()</a>, ConnectTimeout::timeout()) -&gt; {ok, pid()} | {error, term()}</code>


This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

<code>start_link(Host::<a href="#type-host">host()</a>, Port::<a href="inet.md#type-port_number">inet:port_number()</a>, Database::string(), Password::string(), ReconnectSleep::<a href="#type-reconnect_sleep">reconnect_sleep()</a>, ConnectTimeout::timeout(), SocketOptions::list()) -&gt; {ok, pid()} | {error, term()}</code>


This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

stop/1

<code>stop(Client::<a href="#type-client">client()</a>) -&gt; ok</code>


Closes the connection and stops the client.