Packages
redix
0.2.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
defmodule URIError do
@moduledoc """
Error in parsing a Redis URI or error in the content of the URI.
"""
defexception [:message]
end
@spec opts_from_uri(binary) :: Keyword.t
def opts_from_uri(uri) when is_binary(uri) do
uri = URI.parse(uri)
ensure_scheme_is_redis!(uri)
%URI{host: host, port: port} = uri
reject_nils([
host: host,
port: port,
password: password(uri),
database: db(uri),
])
end
defp ensure_scheme_is_redis!(%URI{scheme: "redis"}),
do: :ok
defp ensure_scheme_is_redis!(%URI{scheme: scheme}),
do: raise(URIError, message: "scheme is not redis:// but '#{scheme}://'")
defp password(%URI{userinfo: nil}) do
nil
end
defp password(%URI{userinfo: userinfo}) do
[_user, password] = String.split(userinfo, ":", parts: 2)
password
end
defp db(%URI{path: nil}), do: nil
defp db(%URI{path: "/"}), do: nil
defp db(%URI{path: "/" <> db}), do: String.to_integer(db)
defp reject_nils(opts) when is_list(opts) do
Enum.reject(opts, &match?({_, nil}, &1))
end
end