Skip to content

Commit 2fb032d

Browse files
committed
Update nebulex
1 parent 2c2ea47 commit 2fb032d

File tree

6 files changed

+108
-16
lines changed

6 files changed

+108
-16
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ jobs:
1919
matrix:
2020
include:
2121
- elixir: 1.18.x
22-
otp: 27.x
22+
otp: 28.x
2323
os: 'ubuntu-latest'
2424
lint: true
2525
coverage: true
2626
dialyzer: true
27+
- elixir: 1.17.x
28+
otp: 27.x
29+
os: 'ubuntu-latest'
2730
- elixir: 1.15.x
2831
otp: 25.x
2932
os: 'ubuntu-latest'
@@ -94,13 +97,13 @@ jobs:
9497
- name: Run tests
9598
run: |
9699
epmd -daemon
97-
mix test --exclude nebulex_test
100+
mix test --exclude cluster_queryable_test --exclude redis_cluster
98101
if: ${{ !matrix.coverage }}
99102

100103
- name: Run tests with coverage
101104
run: |
102105
epmd -daemon
103-
mix coveralls.json --exclude nebulex_test
106+
mix coveralls.json --exclude cluster_queryable_test
104107
if: ${{ matrix.coverage }}
105108

106109
- name: Upload coverage reports to Codecov

mix.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ defmodule Nebulex.Adapters.Redis.MixProject do
33

44
@source_url "http://github.com/elixir-nebulex/nebulex_redis_adapter"
55
@version "3.0.0-rc.1"
6-
@nbx_tag "3.0.0-rc.1"
7-
@nbx_vsn "3.0.0-rc.1"
6+
# @nbx_tag "3.0.0-rc.1"
7+
# @nbx_vsn "3.0.0-rc.1"
88

99
def project do
1010
[
@@ -76,15 +76,15 @@ defmodule Nebulex.Adapters.Redis.MixProject do
7676
if path = System.get_env("NEBULEX_PATH") do
7777
{:nebulex, path: path}
7878
else
79-
{:nebulex, "~> #{@nbx_vsn}"}
79+
{:nebulex, github: "elixir-nebulex/nebulex"}
8080
end
8181
end
8282

8383
defp aliases do
8484
[
8585
"nbx.setup": [
8686
"cmd rm -rf nebulex",
87-
"cmd git clone --depth 1 --branch v#{@nbx_tag} http://github.com/elixir-nebulex/nebulex"
87+
"cmd git clone --depth 1 --branch main http://github.com/elixir-nebulex/nebulex"
8888
],
8989
"test.ci": [
9090
"deps.unlock --check-unused",

mix.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
"crc": {:hex, :crc, "0.10.5", "ee12a7c056ac498ef2ea985ecdc9fa53c1bfb4e53a484d9f17ff94803707dfd8", [:mix, :rebar3], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "3e673b6495a9525c5c641585af1accba59a1eb33de697bedf341e247012c2c7f"},
77
"credo": {:hex, :credo, "1.7.12", "9e3c20463de4b5f3f23721527fcaf16722ec815e70ff6c60b86412c695d426c1", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8493d45c656c5427d9c729235b99d498bd133421f3e0a683e5c1b561471291e5"},
88
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
9-
"dialyxir": {:hex, :dialyxir, "1.4.5", "ca1571ac18e0f88d4ab245f0b60fa31ff1b12cbae2b11bd25d207f865e8ae78a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "b0fb08bb8107c750db5c0b324fa2df5ceaa0f9307690ee3c1f6ba5b9eb5d35c3"},
9+
"dialyxir": {:hex, :dialyxir, "1.4.6", "7cca478334bf8307e968664343cbdb432ee95b4b68a9cba95bdabb0ad5bdfd9a", [:mix], [{:erlex, ">= 0.2.7", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "8cf5615c5cd4c2da6c501faae642839c8405b49f8aa057ad4ae401cb808ef64d"},
1010
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
1111
"elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"},
1212
"erlex": {:hex, :erlex, "0.2.7", "810e8725f96ab74d17aac676e748627a07bc87eb950d2b83acd29dc047a30595", [:mix], [], "hexpm", "3ed95f79d1a844c3f6bf0cea61e0d5612a42ce56da9c03f01df538685365efb0"},
13-
"ex_doc": {:hex, :ex_doc, "0.38.0", "0ab17291b71f9b2c479c0b92404107ac5005214872c3b43f845f6f644ba14f56", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "dee6d6485ef501384fbfc7c90cb0fe621636078bebc0f7a1fd2ddcc20b185013"},
13+
"ex_doc": {:hex, :ex_doc, "0.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"},
1414
"ex_hash_ring": {:hex, :ex_hash_ring, "6.0.4", "bef9d2d796afbbe25ab5b5a7ed746e06b99c76604f558113c273466d52fa6d6b", [:mix], [], "hexpm", "89adabf31f7d3dfaa36802ce598ce918e9b5b33bae8909ac1a4d052e1e567d18"},
1515
"excoveralls": {:hex, :excoveralls, "0.18.5", "e229d0a65982613332ec30f07940038fe451a2e5b29bce2a5022165f0c9b157e", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "523fe8a15603f86d64852aab2abe8ddbd78e68579c8525ae765facc5eae01562"},
1616
"file_system": {:hex, :file_system, "1.1.0", "08d232062284546c6c34426997dd7ef6ec9f8bbd090eb91780283c9016840e8f", [:mix], [], "hexpm", "bfcf81244f416871f2a2e15c1b515287faa5db9c6bcf290222206d120b3d43f6"},
17-
"ham": {:hex, :ham, "0.3.0", "7cd031b4a55fba219c11553e7b13ba73bd86eab4034518445eff1e038cb9a44d", [:mix], [], "hexpm", "7d6c6b73d7a6a83233876cc1b06a4d9b5de05562b228effda4532f9a49852bf6"},
17+
"ham": {:hex, :ham, "0.3.2", "02ae195f49970ef667faf9d01bc454fb80909a83d6c775bcac724ca567aeb7b3", [:mix], [], "hexpm", "b71cc684c0e5a3d32b5f94b186770551509e93a9ae44ca1c1a313700f2f6a69a"},
1818
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
1919
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
2020
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
2121
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
22-
"mimic": {:hex, :mimic, "1.11.2", "6449c3b0faee9eb95a86c50752cac4062aa002226128a6e656d020523df8b9e5", [:mix], [{:ham, "~> 0.2", [hex: :ham, repo: "hexpm", optional: false]}], "hexpm", "4856ce771c96e3d115b56f931499b2178246bbb314bcc1f80369dfda754c4912"},
23-
"nebulex": {:hex, :nebulex, "3.0.0-rc.1", "7df321576a43f20ba390fdf67e91cefd0e1b335c275fa014310210224d7ebba2", [:mix], [{:decorator, "~> 1.4", [hex: :decorator, repo: "hexpm", optional: true]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "0b09b3562df1d6d0186ba411d213db9a3c5ebf7ac6cdb88cdc3d735d8f9a0311"},
22+
"mimic": {:hex, :mimic, "1.12.0", "34c9d1fb8e756df09ca5f96861d273f2bb01063df1a6a51a4c101f9ad7f07a9c", [:mix], [{:ham, "~> 0.2", [hex: :ham, repo: "hexpm", optional: false]}], "hexpm", "eaa43d495d6f3bc8099b28886e05a1b09a2a6be083f6385c3abc17599e5e2c43"},
23+
"nebulex": {:git, "https://github.com/elixir-nebulex/nebulex.git", "23b7481ba4603d77e55976cf261ff15c42ce77d9", []},
2424
"nimble_options": {:hex, :nimble_options, "1.1.1", "e3a492d54d85fc3fd7c5baf411d9d2852922f66e69476317787a7b2bb000a61b", [:mix], [], "hexpm", "821b2470ca9442c4b6984882fe9bb0389371b8ddec4d45a9504f00a66f650b44"},
2525
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
2626
"redix": {:hex, :redix, "1.5.2", "ab854435a663f01ce7b7847f42f5da067eea7a3a10c0a9d560fa52038fd7ab48", [:mix], [{:castore, "~> 0.1.0 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:nimble_options, "~> 0.5.0 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "78538d184231a5d6912f20567d76a49d1be7d3fca0e1aaaa20f4df8e1142dcb8"},
27-
"statistex": {:hex, :statistex, "1.0.0", "f3dc93f3c0c6c92e5f291704cf62b99b553253d7969e9a5fa713e5481cd858a5", [:mix], [], "hexpm", "ff9d8bee7035028ab4742ff52fc80a2aa35cece833cf5319009b52f1b5a86c27"},
27+
"statistex": {:hex, :statistex, "1.1.0", "7fec1eb2f580a0d2c1a05ed27396a084ab064a40cfc84246dbfb0c72a5c761e5", [:mix], [], "hexpm", "f5950ea26ad43246ba2cce54324ac394a4e7408fdcf98b8e230f503a0cba9cf5"},
2828
"stream_data": {:hex, :stream_data, "1.2.0", "58dd3f9e88afe27dc38bef26fce0c84a9e7a96772b2925c7b32cd2435697a52b", [:mix], [], "hexpm", "eb5c546ee3466920314643edf68943a5b14b32d1da9fe01698dc92b73f89a9ed"},
2929
"telemetry": {:hex, :telemetry, "1.3.0", "fedebbae410d715cf8e7062c96a1ef32ec22e764197f70cda73d82778d61e7a2", [:rebar3], [], "hexpm", "7015fc8919dbe63764f4b4b87a95b7c0996bd539e0d499be6ec9d7f3875b79e6"},
3030
}

test/nebulex/adapters/redis/cluster_cache_test.exs renamed to test/nebulex/adapters/redis/cluster_queryable_test.exs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
defmodule Nebulex.Adapters.Redis.ClusterCacheTest do
1+
defmodule Nebulex.Adapters.Redis.ClusterQueryableTest do
22
use ExUnit.Case, async: false
3-
@moduletag :nebulex_test
3+
4+
@moduletag :redis_cluster
5+
@moduletag :cluster_queryable_test
46
@moduletag capture_log: true
57

68
# Inherited tests from Nebulex

test/nebulex/adapters/redis/cluster_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
defmodule Nebulex.Adapters.Redis.ClusterTest do
22
use ExUnit.Case, async: false
3+
4+
@moduletag :redis_cluster
35
@moduletag capture_log: true
46

57
use Mimic

test/nebulex/adapters/redis/standalone_test.exs

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule Nebulex.Adapters.Redis.StandaloneTest do
66
use Nebulex.Adapters.Redis.CacheTest
77
use Nebulex.CacheTestCase, except: [Nebulex.Cache.TransactionTest]
88

9-
import Nebulex.CacheCase, only: [safe_stop: 1]
9+
import Nebulex.CacheCase, only: [safe_stop: 1, t_sleep: 1]
1010

1111
alias Nebulex.Adapters.Redis.TestCache.Standalone, as: Cache
1212

@@ -19,4 +19,89 @@ defmodule Nebulex.Adapters.Redis.StandaloneTest do
1919

2020
{:ok, cache: Cache, name: Cache}
2121
end
22+
23+
describe "KV API" do
24+
test "fetch_or_store stores the value in the cache if the key does not exist", %{cache: cache} do
25+
assert cache.fetch_or_store("lazy", fn -> {:ok, "value"} end) == {:ok, "value"}
26+
assert cache.get!("lazy") == "value"
27+
28+
assert cache.fetch_or_store("lazy", fn -> {:ok, "new value"} end) == {:ok, "value"}
29+
assert cache.get!("lazy") == "value"
30+
end
31+
32+
test "fetch_or_store returns error if the function returns an error", %{cache: cache} do
33+
assert {:error, %Nebulex.Error{reason: "error"}} =
34+
cache.fetch_or_store("lazy", fn -> {:error, "error"} end)
35+
36+
refute cache.get!("lazy")
37+
end
38+
39+
test "fetch_or_store raises if the function returns an invalid value", %{cache: cache} do
40+
msg =
41+
"the supplied lambda function must return {:ok, value} or " <>
42+
"{:error, reason}, got: :invalid"
43+
44+
assert_raise RuntimeError, msg, fn ->
45+
cache.fetch_or_store!("lazy", fn -> :invalid end)
46+
end
47+
end
48+
49+
test "fetch_or_store! stores the value in the cache if the key does not exist", %{cache: cache} do
50+
assert cache.fetch_or_store!("lazy", fn -> {:ok, "value"} end) == "value"
51+
assert cache.get!("lazy") == "value"
52+
53+
assert cache.fetch_or_store!("lazy", fn -> {:ok, "new value"} end) == "value"
54+
assert cache.get!("lazy") == "value"
55+
end
56+
57+
test "fetch_or_store! raises if an error occurs", %{cache: cache} do
58+
assert_raise Nebulex.Error, ~r"error", fn ->
59+
cache.fetch_or_store!("lazy", fn -> {:error, "error"} end)
60+
end
61+
62+
refute cache.get!("lazy")
63+
end
64+
65+
test "fetch_or_store! stores the value with TTL", %{cache: cache} do
66+
assert cache.fetch_or_store!("lazy", fn -> {:ok, "value"} end, ttl: :timer.seconds(1)) ==
67+
"value"
68+
69+
assert cache.get!("lazy") == "value"
70+
71+
_ = t_sleep(:timer.seconds(1) + 100)
72+
73+
assert cache.fetch_or_store!("lazy", fn -> {:ok, "new value"} end, ttl: :timer.seconds(1)) ==
74+
"new value"
75+
76+
assert cache.get!("lazy") == "new value"
77+
end
78+
79+
test "get_or_store stores what the function returns if the key does not exist", %{cache: cache} do
80+
["value", {:ok, "value"}, {:error, "error"}]
81+
|> Enum.with_index()
82+
|> Enum.each(fn {ret, i} ->
83+
assert cache.get_or_store(i, fn -> ret end) == {:ok, ret}
84+
assert cache.get!(i) == ret
85+
end)
86+
end
87+
88+
test "get_or_store! stores what the function returns if the key does not exist", %{cache: cache} do
89+
["value", {:ok, "value"}, {:error, "error"}]
90+
|> Enum.with_index()
91+
|> Enum.each(fn {ret, i} ->
92+
assert cache.get_or_store!(i, fn -> ret end) == ret
93+
assert cache.get!(i) == ret
94+
end)
95+
end
96+
97+
test "get_or_store! stores the value with TTL", %{cache: cache} do
98+
assert cache.get_or_store!("ttl", fn -> "value" end, ttl: :timer.seconds(1)) == "value"
99+
assert cache.get!("ttl") == "value"
100+
101+
_ = t_sleep(:timer.seconds(1) + 100)
102+
103+
assert cache.get_or_store!("ttl", fn -> "new value" end) == "new value"
104+
assert cache.get!("ttl") == "new value"
105+
end
106+
end
22107
end

0 commit comments

Comments
 (0)