Redix problem connecting mix to redis

Hi Elixir team! I am new to this forum. I currently moved to redis sentinel and although production is working fine I am having trouble getting my tests to pass. The error I am seeing is: ** (Mix) Could not start application scrivener: Scrivener.start(:normal, []) returned an error: shutdown: failed to start child: :worker ** (EXIT) an exception was raised: ** (MatchError) no match of right hand side value: {:error, {:EXIT, {%ArgumentError{message: "sentinel address should be specified as a URI or a keyword list, got: nil"}, [{Redix.StartOptions, :normalize_sentinel_address, 2, [file: 'lib/redix/start_options.ex', line: 122]}, {Enum, :"-map/2-lists^map/1-0-", 2, [file: 'lib/enum.ex', line: 1411]}, {Redix.StartOptions, :sanitize_sentinel_opts, 1, [file: 'lib/redix/start_options.ex', line: 79]}, {Redix.StartOptions, :maybe_sanitize_sentinel_opts, 1, [file: 'lib/redix/start_options.ex', line: 68]}, {Redix.StartOptions, :sanitize, 1, [file: 'lib/redix/start_options.ex', line: 51]}, {Redix.Connection, :start_link, 1, [file: 'lib/redix/connection.ex', line: 25]}, {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 385]}, {:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 410]}]}}} (poolboy 1.5.1) src/poolboy.erl:275: :poolboy.new_worker/1 . My test.exs is set up exactly like my prod.exs => ```config :scrivener, Scrivener.Endpoint,
http: [:inet6, port: {:system, “PORT”}],
server: false

Do not print debug messages in production

config :logger, level: :warn

Pull Redis sentinel settings from environment variables

{ redis_pool_size, original_value } = (System.get_env(“REDIS_POOL_SIZE”) || “5”) |> Integer.parse
{ redis_max_overflow, original_value } = (System.get_env(“REDIS_MAX_OVERFLOW”) || “2”) |> Integer.parse
{ redis_sentinel_timeout, original_value } = (System.get_env(“REDIS_SENTINEL_TIMEOUT”) || “10000”) |> Integer.parse

config :redix,
pool_size: redis_pool_size,
max_overflow: redis_max_overflow,
sentinel: [
sentinels: [
System.get_env(“REDIS_SENTINEL_HOST_A”),
System.get_env(“REDIS_SENTINEL_HOST_B”),
System.get_env(“REDIS_SENTINEL_HOST_C”)
],
group: System.get_env(“REDIS_SENTINEL_GROUP”),
timeout: redis_sentinel_timeout
]```. I can see it is a redix issue but not sure how to resolve.

I suspect one of these environment variables isn’t set, that would explain finding a nil in sentinels

1 Like

Thanks for the fast reply. By checking my environment variables, I have them connected and they are working in production. I am wondering if it could be a gem/version thing for mix? REDIS_SENTINEL_HOST_A=redis://sentinel004…
REDIS_SENTINEL_HOST_B=redis://sentinel005…
REDIS_SENTINEL_HOST_C=redis://sentinel006…

Try inspecting the values in the config; something is not making it to Redix.

config :redix,
  pool_size: redis_pool_size,
  max_overflow: redis_max_overflow,
  sentinel: [
    sentinels: [
      System.get_env(“REDIS_SENTINEL_HOST_A”),
      System.get_env(“REDIS_SENTINEL_HOST_B”),
      System.get_env(“REDIS_SENTINEL_HOST_C”)
    ] |> IO.inspect(label: "sentinel list"),
    group: System.get_env(“REDIS_SENTINEL_GROUP”),
    timeout: redis_sentinel_timeout
  ]
1 Like

Thank you :bowing_man:. It looks like when printing they were coming in as null. I hardcoded redis sentinel endpoints and following error: {%ArgumentError{message: “a host should be specified for each sentinel”}. When looking in redix docs, I see {Redix supports Redis Sentinel by passing a :sentinel
option to start_link/1 (or start_link/2) instead of :host and :port.}. Which is how it looks like I set it up.

1 Like

It is unclear from the last message if you managed to solve this issue or not, but the fact that your settings were printed as nil would indicate that you tried to set the values using environment variables during runtime, hoping that they would be injected in the config. However, that code that is actually executed at compile-time.

You mentioned the injection of these variables in your config/test.exs and config/prod.exs reinforces my impression. Most likely, you have such variables correctly set in your test suite, but you most certainly don’t have them when compiling your code for production. Both config files mentioned above are only executed during compile-time, and therefor, only use the environment variables available at that point in time. Setting these variables later, when running the application, is irrelevant.

The only config file executed during runtime is config/releases.exs, but obviously only in the context of a release, which is what you should be running in production anyway.