Redix.command
command
, go back to Redix module for more information.
Specs
command(connection(), command(), keyword()) :: {:ok, Redix.Protocol.redis_value()} | {:error, atom() | Redix.Error.t() | Redix.ConnectionError.t()}
Issues a command on the Redis server.
This function sends command
to the Redis server and returns the response
returned by Redis. pid
must be the pid of a Redix connection. command
must
be a list of strings making up the Redis command and its arguments.
The return value is {:ok, response}
if the request is successful and the
response is not a Redis error. {:error, reason}
is returned in case there's
an error in the request (such as losing the connection to Redis in between the
request). reason
can also be a Redix.Error
exception in case Redis is
reachable but returns an error (such as a type error).
If the given command is an empty command ([]
), an ArgumentError
exception is raised.
This function accepts the same options as pipeline/3
.
Examples
iex> Redix.command(conn, ["SET", "mykey", "foo"])
{:ok, "OK"}
iex> Redix.command(conn, ["GET", "mykey"])
{:ok, "foo"}
iex> Redix.command(conn, ["INCR", "mykey"])
{:error, "ERR value is not an integer or out of range"}
If Redis goes down (before a reconnection happens):
iex> {:error, error} = Redix.command(conn, ["GET", "mykey"])
iex> error.reason
:closed