View Source Module eredis

Data Types

client()

client() = pid() | atom() | {atom(), atom()} | {global, term()} | {via, atom(), term()}

host()

host() = string() | {local, string()}

obfuscated()

obfuscated() = fun(() -> iodata())

option()

option() = {host, string() | {local, string()}} | {port, inet:port_number()} | {database, integer()} | {username, iodata() | obfuscated() | undefined} | {password, iodata() | obfuscated() | undefined} | {reconnect_sleep, reconnect_sleep()} | {connect_timeout, integer()} | {socket_options, list()} | {tls, [ssl:tls_client_option()]} | {name, registered_name()} | {sentinel, list()}

options()

options() = [option()]

pipeline()

pipeline() = [iolist()]

reconnect_sleep()

reconnect_sleep() = no_reconnect | integer()

registered_name()

registered_name() = {local, atom()} | {global, term()} | {via, atom(), term()}

return_value()

return_value() = undefined | binary() | [binary() | nonempty_list()]

Function Index

q/2 Executes the given command in the specified connection.
q/3Like q/2 with a custom timeout.
q_async/2Executes the command, and sends a message to the calling process with theresponse (with either error or success).
q_async/3Executes the command, and sends a message to Pid with the response (with either or success).
q_noreply/2Executes the command but does not wait for a response and ignores any errors.
qp/2 Executes the given pipeline (list of commands) in the specified connection.
qp/3Like qp/2 with a custom timeout.
start_link/0Connect with default options.
start_link/1Connect with the given options.
start_link/2Connect to the given host and port.
start_link/3(Deprecated.)
start_link/4(Deprecated.)
start_link/5(Deprecated.)
start_link/6(Deprecated.)
start_link/7(Deprecated.)
stop/1Closes the connection and stops the client.

Function Details

q/2

q(Client::client(), Command::[any()]) -> {ok, return_value()} | {error, Reason::binary() | no_connection}

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

q(Client::client(), Command::[any()], Timeout::timeout()) -> {ok, return_value()} | {error, Reason::binary() | no_connection}

Like q/2 with a custom timeout.

q_async/2

q_async(Client::client(), Command::[any()]) -> ok

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

q_async(Client::client(), Command::[any()], Pid::pid() | atom()) -> ok

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

See also: q_async/2.

q_noreply/2

q_noreply(Client::client(), Command::[any()]) -> ok

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

See also: q/2.

qp/2

qp(Client::client(), Pipeline::pipeline()) -> [{ok, return_value()} | {error, Reason::binary()}] | {error, no_connection}

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

qp(Client::client(), Pipeline::pipeline(), Timeout::timeout()) -> [{ok, return_value()} | {error, Reason::binary()}] | {error, no_connection}

Like qp/2 with a custom timeout.

start_link() -> {ok, Pid::pid()} | {error, Reason::term()}

Equivalent to start_link([]).

Connect with default options.

start_link(Options::options()) -> {ok, pid()} | {error, Reason::term()}

Options:

{host, Host}
DNS name or IP address as string; or unix domain socket as {local, Path} (available in OTP 19+); default "127.0.0.1"
{port, Port}
Integer, default is 6379
{database, Database}
Integer; 0 for the default database
{username, Username}
A 0-ary function that returns the username (the preferred way to provide username as it prevents the actual secret from appearing in logs and stacktraces), a string or iodata or the atom undefined for no username; default undefined
{password, Password}
A 0-ary function that returns the password (the preferred way to provide password as it prevents the actual secret from appearing in logs and stacktraces), a string or iodata or the atom undefined for no password; default undefined
{reconnect_sleep, ReconnectSleep}
Integer of milliseconds to sleep between reconnect attempts; default: 100
{connect_timeout, Timeout}
Timeout value in milliseconds to use when connecting to Redis; default: 5000
{socket_options, SockOpts}
List ofgen_tcp options used when connecting the socket; default is ?SOCKET_OPTS
{tls, TlsOpts}
Enabling TLS and a list ofssl options; used when establishing a TLS connection; default is off
{name, Name}
Tuple to register the client with a name such as {local, atom()}; for all options see ServerName atgen_server:start_link/4; default: no name
{sentinel, SentinelOptions}
Enables client for sentinel mode; options are required to connect to sentinel cluster; default: undefined
Sentinel Options: {master_group, master_group_name} - Atom, default: mymaster;{endpoints, [{Host, Port}]} - List of {Host, Port} tuples, default: [{"127.0.0.1", 26379}];{username, Username};{password, Password};{connect_timeout, Timeout};{socket_options, SockOpts}{tls, TlsOpts}

Connect with the given options.

start_link(Host::host(), Port::inet:port_number()) -> {ok, Pid::pid()} | {error, Reason::term()}

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

Connect to the given host and port.

start_link(Host::host(), Port::inet:port_number(), OptionsOrDatabase) -> {ok, Pid::pid()} | {error, Reason::term()}

This function is deprecated: Use start_link/1 instead.

start_link(Host::host(), Port::inet:port_number(), Database::integer(), Password::string()) -> {ok, pid()} | {error, term()}

This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

start_link(Host::host(), Port::inet:port_number(), Database::integer(), Password::string(), ReconnectSleep::reconnect_sleep()) -> {ok, pid()} | {error, term()}

This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

start_link(Host::host(), Port::inet:port_number(), Database::integer(), Password::string(), ReconnectSleep::reconnect_sleep(), ConnectTimeout::timeout()) -> {ok, pid()} | {error, term()}

This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

start_link(Host::host(), Port::inet:port_number(), Database::integer(), Password::string(), ReconnectSleep::reconnect_sleep(), ConnectTimeout::timeout(), SocketOptions::list()) -> {ok, pid()} | {error, term()}

This function is deprecated: Use start_link/1 instead.

See also: start_link/1.

stop/1

stop(Client::client()) -> ok

Closes the connection and stops the client.