Skip to content

Commit

Permalink
handle nil return (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
CorneliaKelinske committed Jun 2, 2023
1 parent 02ccb32 commit f49ccae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cache/term_encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ defmodule Cache.TermEncoder do
value
end

def decode_json(nil), do: nil
def decode_json(json) do
case Jason.decode(json) do
{:ok, data} -> data
Expand Down
4 changes: 4 additions & 0 deletions test/cache/redis_json_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ defmodule Cache.RedisJSONTest do
"some_map" => %{"one" => 1, "two" => 2, "three" => 3, "four" => 4}
}} === RedisCache.json_get(key)
end

test "returns :ok and nil if key not found" do
assert {:ok, nil} === RedisCache.json_get("non_existing")
end
end

describe "&json_get/2" do
Expand Down

0 comments on commit f49ccae

Please sign in to comment.