Packages
redix
0.8.1
1.6.0
1.5.3
1.5.2
1.5.1
1.5.0
1.4.2
1.4.1
1.4.0
1.3.0
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.5
1.1.4
1.1.3
1.1.2
1.1.1
retired
1.1.0
1.0.0
0.11.2
0.11.1
0.11.0
0.10.7
0.10.6
0.10.5
0.10.4
0.10.3
0.10.2
0.10.1
0.10.0
0.9.3
0.9.2
0.9.1
0.9.0
0.8.2
0.8.1
0.8.0
0.7.1
0.7.0
0.6.1
0.6.0
0.5.2
0.5.1
0.5.0
0.4.0
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.0
Fast, pipelined, resilient Redis driver for Elixir.
Current section
Files
Jump to
Current section
Files
lib/redix/uri.ex
defmodule Redix.URI do
@moduledoc false
@spec opts_from_uri(binary) :: Keyword.t()
def opts_from_uri(uri) when is_binary(uri) do
%URI{host: host, port: port, scheme: scheme} = uri = URI.parse(uri)
unless scheme == "redis" do
raise ArgumentError, "expected scheme to be redis://, got: #{scheme}://"
end
[]
|> Keyword.put(:host, host)
|> Keyword.put(:port, port)
|> put_if_not_nil(:password, password(uri))
|> put_if_not_nil(:database, database(uri))
end
defp password(%URI{userinfo: nil}) do
nil
end
defp password(%URI{userinfo: userinfo}) do
[_user, password] = String.split(userinfo, ":", parts: 2)
password
end
defp database(%URI{path: path}) when path in [nil, "/"], do: nil
defp database(%URI{path: "/" <> db}), do: String.to_integer(db)
defp put_if_not_nil(opts, _key, nil), do: opts
defp put_if_not_nil(opts, key, value), do: Keyword.put(opts, key, value)
end