File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -64,17 +64,27 @@ defmodule CesiumLink.Links do
64
64
65
65
"""
66
66
def list_unarchived_links_by_index do
67
- case CesiumLink.Standalone . get ( "links" ) do
68
- nil ->
67
+ case safe_get_from_redis ( "links" ) do
68
+ { :ok , nil } ->
69
69
links = list_unarchived_links_by_index_from_db ( )
70
70
CesiumLink.Standalone . put ( "links" , links )
71
71
links
72
72
73
- links ->
73
+ { :ok , links } ->
74
74
links
75
+
76
+ { :error , _reason } ->
77
+ list_unarchived_links_by_index_from_db ( )
75
78
end
76
79
end
77
80
81
+ defp safe_get_from_redis ( key ) do
82
+ { :ok , CesiumLink.Standalone . get ( key ) }
83
+ rescue
84
+ exception ->
85
+ { :error , exception }
86
+ end
87
+
78
88
def list_unarchived_links_by_index_from_db do
79
89
Repo . all ( from l in Link , where: l . archived == false , order_by: [ asc: l . index ] )
80
90
end
Original file line number Diff line number Diff line change 1
1
defmodule CesiumLink.Standalone do
2
+ @ moduledoc """
3
+ Standalone redis cache.
4
+ """
2
5
use Nebulex.Cache ,
3
6
otp_app: :safira ,
4
7
adapter: NebulexRedisAdapter
You can’t perform that action at this time.
0 commit comments