# Redix example usage

**URL:** <https://forum.elixirforum.com/t/redix-example-usage/21489>\
**Category:** Questions\
**Tags:** phoenix, redix\
**Created:** [April 8, 2019, 3:48pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489 "2019-04-08T15:48:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jihantoro](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jihantoro/32/16385_2.png) [@jihantoro](https://forum.elixirforum.com/u/jihantoro)\
**Post date:** [April 8, 2019, 3:48pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/1 "2019-04-08T15:48:09Z")

</div>

hi, i’m trying to use redis with my phoenix app, but confused where i must define the `conn` variable, can i just define it in config file ? and call Redix anywhere ? thank you

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nobbz/32/27235_2.png) [@NobbZ](https://forum.elixirforum.com/u/NobbZ)\
**Post date:** [April 8, 2019, 3:51pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/2 "2019-04-08T15:51:51Z")

</div>

From the documentation ([Redix — Redix v1.5.3](https://hexdocs.pm/redix/readme.html#usage)) it seems as if it were returned by `Redix.start_link`.

---

<div class="post-metadata">

**Author:** ![jihantoro](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jihantoro/32/16385_2.png) [@jihantoro](https://forum.elixirforum.com/u/jihantoro)\
**Post date:** [April 8, 2019, 3:55pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/3 "2019-04-08T15:55:02Z")

</div>

```elixir
defmodule DigitalWeb.PageController do
  use DigitalWeb, :controller

  def use_redix(conn, _params) do
  	{:ok, conn} = Redix.start_link("redis://localhost:6379/3", name: :redix)
  	Redix.command(conn, ["SET", "mykey", "foo"])
  end

  def use_redix_again(conn, _params) do
  	{:ok, conn} = Redix.start_link("redis://localhost:6379/3", name: :redix)
  	Redix.command(conn, ["SET", "mykey", "foo"])
  end
end

```

i mean, i want to define `start_link` once, and call Redix.command everywhere

---

<div class="post-metadata">

**Author:** ![goofansu](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/goofansu/32/18325_2.png) [@goofansu](https://forum.elixirforum.com/u/goofansu)\
**Post date:** [April 8, 2019, 4:04pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/4 "2019-04-08T16:04:10Z")

</div>

> [@jihantoro](#):
>
> i mean, i want to define `start_link` once, and call Redix.command everywhere

There is a chapter [Real-world usage](https://hexdocs.pm/redix/real-world-usage.html).

---

<div class="post-metadata">

**Author:** ![jihantoro](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jihantoro/32/16385_2.png) [@jihantoro](https://forum.elixirforum.com/u/jihantoro)\
**Post date:** [April 8, 2019, 4:11pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/5 "2019-04-08T16:11:08Z")

</div>

geez, yeah, by default, add `{Redix, name: :redix}` in lib/appname/application.ex

---

<div class="post-metadata">

**Author:** ![shahryarjb](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/shahryarjb/32/39485_2.png) [@shahryarjb](https://forum.elixirforum.com/u/shahryarjb)\
**Post date:** [October 18, 2019, 9:18am UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/6 "2019-10-18T09:18:26Z")

</div>

> [@jihantoro](#):
>
> `{Redix, name: :redix}`

when I use this I have this error: `{:error, %Redix.Error{message: "NOAUTH Authentication required."}`  
how can I import my Redis Password on it ?

```elixir
iex(2)> Redix.command(:redix, ["PING"])
{:error, %Redix.Error{message: "NOAUTH Authentication required."}}

```

---

<div class="post-metadata">

**Author:** ![jihantoro](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jihantoro/32/16385_2.png) [@jihantoro](https://forum.elixirforum.com/u/jihantoro)\
**Post date:** [October 18, 2019, 9:35am UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/7 "2019-10-18T09:35:59Z")

</div>

here you go [lib/redix/start\_options.ex#L21](https://github.com/whatyouhide/redix/blob/57e7f49622445c7f61b1f54204e89a05b45e21d0/lib/redix/start_options.ex#L21)

```elixir
{Redix, name: :redix, password: "password"}

```

---

<div class="post-metadata">

**Author:** ![koolquark](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/koolquark/32/29615_2.png) [@koolquark](https://forum.elixirforum.com/u/koolquark)\
**Post date:** [February 24, 2023, 8:09pm UTC](https://forum.elixirforum.com/t/redix-example-usage/21489/8 "2023-02-24T20:09:13Z")

</div>

code is the ultimate doc
