diff --git a/.dialyzer_ignore b/.dialyzer_ignore new file mode 100644 index 0000000..38b22ca --- /dev/null +++ b/.dialyzer_ignore @@ -0,0 +1 @@ +lib/cream/continuum.ex:42: Guard test _@1::'true' =:= 'false' can never succeed diff --git a/lib/cream/cluster.ex b/lib/cream/cluster.ex index 82c4185..8bd6717 100644 --- a/lib/cream/cluster.ex +++ b/lib/cream/cluster.ex @@ -53,10 +53,15 @@ defmodule Cream.Cluster do """ @type item :: {key, value} + @typedoc """ + Multiple items as a map. + """ + @type items_map :: %{required(key) => value} + @typedoc """ Multiple items as a list of tuples or a map. """ - @type items :: [item] | [%{required(key) => value}] + @type items :: [item] | items_map @typedoc """ Reason associated with an error. @@ -286,8 +291,9 @@ defmodule Cream.Cluster do set(cluster, %{k1 => v1, k2 => v2}, ttl: 300) ``` """ - @spec set(t, item | items, Keyword.t) :: :ok | {:error, reason} - def set(cluster, item_or_items, opts \\ []) + @spec set(t, item, Keyword.t()) :: :ok | {:error, reason} + @spec set(t, items, Keyword.t()) :: %{required(key) => :ok | {:error, reason}} + def set(cluster, item_or_items, opts \\ []) def set(cluster, items, opts) when is_list(items) or is_map(items) do with_worker cluster, fn worker -> @@ -310,8 +316,8 @@ defmodule Cream.Cluster do %{"foo" => "bar", "one" => "one"} = get(pid, ["foo", "bar"]) ``` """ - @spec get(t, key, Keyword.t) :: value - @spec get(t, keys, Keyword.t) :: items + @spec get(t, key, Keyword.t) :: value | nil + @spec get(t, keys, Keyword.t) :: items_map def get(cluster, key_or_keys, opts \\ []) def get(cluster, key, opts) when is_binary(key) do diff --git a/lib/cream/cluster/worker.ex b/lib/cream/cluster/worker.ex index bbcc44a..fd661bc 100644 --- a/lib/cream/cluster/worker.ex +++ b/lib/cream/cluster/worker.ex @@ -28,7 +28,12 @@ defmodule Cream.Cluster.Worker do end reply = Enum.reduce pairs_by_conn, %{}, fn {conn, pairs}, acc -> - {:ok, responses} = Memcache.multi_set(conn, pairs, options) + responses = case Memcache.multi_set(conn, pairs, options) do + {:ok, results} -> results + {:error, reason} when is_atom(reason) -> Enum.map(pairs, fn _ -> + {:error, Atom.to_string(reason)} + end) + end Enum.zip(pairs, responses) |> Enum.reduce(acc, fn {pair, status}, acc -> diff --git a/mix.exs b/mix.exs index fcdff1c..89f3e05 100644 --- a/mix.exs +++ b/mix.exs @@ -24,7 +24,8 @@ defmodule Cream.Mixfile do "README.md": [title: "README"], "CHANGELOG.md": [title: "CHANGELOG"] ] - ] + ], + dialyzer: [ignore_warnings: ".dialyzer_ignore"] ] end