Skip to content

Commit

Permalink
Drop ~w from the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed May 5, 2017
1 parent aff0094 commit abb3493
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
40 changes: 9 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ connection process under a name).
Commands can be sent using `Redix.command/2-3`:

```elixir
Redix.command(conn, ~w(SET mykey foo))
Redix.command(conn, ["SET", "mykey", "foo"])
#=> {:ok, "OK"}
Redix.command(conn, ~w(GET mykey))
Redix.command(conn, ["GET", "mykey"])
#=> {:ok, "foo"}
```

Expand All @@ -67,7 +67,7 @@ replies with a list of responses. They can be used in Redix via
`Redix.pipeline/2,3`:

```elixir
Redix.pipeline(conn, [~w(INCR foo), ~w(INCR foo), ~w(INCRBY foo 2)])
Redix.pipeline(conn, [["INCR", "foo"], ["INCR", "foo"], ["INCRBY", "foo", "2"]])
#=> {:ok, [1, 2, 4]}
```

Expand All @@ -76,42 +76,20 @@ Redix.pipeline(conn, [~w(INCR foo), ~w(INCR foo), ~w(INCRBY foo 2)])
there's an error, bang! variants are provided:

```elixir
Redix.command!(conn, ~w(PING))
Redix.command!(conn, ["PING"])
#=> "PONG"

Redix.pipeline!(conn, [~w(SET mykey foo), ~w(GET mykey)])
Redix.pipeline!(conn, [["SET", "mykey", "foo"], ["GET", "mykey"]])
#=> ["OK", "foo"]
```

A note about Redis errors: in the non-bang functions, they're returned as
`Redix.Error` structs with a `:message` field which contains the original error
message.

```elixir
Redix.command(conn, ~w(FOO))
#=> {:error, %Redix.Error{message: "ERR unknown command 'FOO'"}}

# pipeline/2 returns {:ok, _} instead of {:error, _} even if there are errors in
# the list of responses so that it doesn't have to walk the entire list of
# responses.
Redix.pipeline(conn, [~w(PING), ~w(FOO)])
#=> {:ok, ["PONG", %Redix.Error{message: "ERR unknown command 'FOO'"}]}
```

In `Redix.command!/2,3`, Redis errors are raised as exceptions:

```elixir
Redix.command!(conn, ~w(FOO))
#=> ** (Redix.Error) ERR unknown command 'FOO'
```

`Redix.command!/2,3` and `Redix.pipeline!/2,3` raise `Redix.ConnectionError` in
case there's an error related to the Redis connection (e.g., the connection is
`Redix.command/2,3` and `Redix.pipeline/2,3` return a `Redix.ConnectionError` struct in
case there's an error related to the Redis connection (for example, the connection is
closed while Redix is waiting to reconnect).

#### Resiliency

Redix takes full advantage of the [connection][connection] library by James
Redix takes full advantage of the [Connection][connection] library by James
Fish to provide a resilient behaviour when dealing with the network connection
to Redis. For example, if the connection to Redis drops, Redix will
automatically try to reconnect to it periodically at a given "backoff" interval
Expand All @@ -123,7 +101,7 @@ reconnections.
#### Pub/Sub

Redix doesn't support the Pub/Sub features of Redis. For that, there's
[`redix_pubsub`][redix-pubsub] :).
[`redix_pubsub`][redix-pubsub].

## Using Redix in the Real World™

Expand Down
12 changes: 6 additions & 6 deletions lib/redix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ defmodule Redix do
## Examples
iex> Redix.pipeline(conn, [~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
iex> Redix.pipeline(conn, [["INCR", "mykey"], ["INCR", "mykey"], ["DECR", "mykey"]])
{:ok, [1, 2, 1]}
iex> Redix.pipeline(conn, [~w(SET k foo), ~w(INCR k), ~(GET k)])
iex> Redix.pipeline(conn, [["SET", "k", "foo"], ["INCR", "k"], ["GET", "k"]])
{:ok, ["OK", %Redix.Error{message: "ERR value is not an integer or out of range"}, "foo"]}
If Redis goes down (before a reconnection happens):
iex> {:error, error} = Redix.pipeline(conn, [~w(SET mykey foo), ~w(GET mykey)])
iex> {:error, error} = Redix.pipeline(conn, [["SET", "mykey", "foo"], ["GET", "mykey"]])
iex> error.reason
:closed
Expand Down Expand Up @@ -257,15 +257,15 @@ defmodule Redix do
## Examples
iex> Redix.pipeline!(conn, [~w(INCR mykey), ~w(INCR mykey), ~w(DECR mykey)])
iex> Redix.pipeline!(conn, [["INCR", "mykey"], ["INCR", "mykey"], ["DECR", "mykey"]])
[1, 2, 1]
iex> Redix.pipeline!(conn, [~w(SET k foo), ~w(INCR k), ~(GET k)])
iex> Redix.pipeline!(conn, [["SET", "k", "foo"], ["INCR", "k"], ["GET", "k"]])
["OK", %Redix.Error{message: "ERR value is not an integer or out of range"}, "foo"]
If Redis goes down (before a reconnection happens):
iex> Redix.pipeline!(conn, [~w(SET mykey foo), ~w(GET mykey)])
iex> Redix.pipeline!(conn, [["SET", "mykey", "foo"], ["GET", "mykey"]])
** (Redix.ConnectionError) :closed
"""
Expand Down
6 changes: 3 additions & 3 deletions pages/Real-world usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Redixes that can be checked out and back in from the pool when needed:

```elixir
:poolboy.checkout(:my_redix_pool, fn redix_pid ->
Redix.command(redix_pid, ~w(PING))
Redix.command(redix_pid, ["PING"])
end)
```

Expand All @@ -42,7 +42,7 @@ children = [
]
```

and then called globally (e.g., `Redix.command(:redix, ~w(PING))`).
and then called globally (for example, `Redix.command(:redix, ["PING"])`).

Note that this pattern extends to more than one global (named) Redix: for
example, you could have a Redix process for handling big and infrequent requests
Expand Down Expand Up @@ -87,7 +87,7 @@ end
And then to use the new wrapper in your appplication:

```elixir
MyApp.Redix.command(~w(PING))
MyApp.Redix.command(["PING"])
```

[poolboy]: https://github.com/devinus/poolboy

0 comments on commit abb3493

Please sign in to comment.