@@ -23,15 +23,6 @@ defmodule ComponentsGuide.Research.Source do
23
23
end
24
24
end
25
25
26
- defp redis_config ( ) do
27
- upstash_config = Application . fetch_env! ( :components_guide , :upstash )
28
-
29
- % {
30
- url: upstash_config [ :redis_rest_url ] ,
31
- token: upstash_config [ :redis_rest_token ]
32
- }
33
- end
34
-
35
26
defp read_redis_cache ( key ) do
36
27
{ duration_microseconds , result } =
37
28
:timer . tc ( fn ->
@@ -48,53 +39,7 @@ defmodule ComponentsGuide.Research.Source do
48
39
49
40
defp write_redis_cache ( key , value ) do
50
41
result = Redix . command ( :upstash_redix , [ "SET" , key , value ] )
51
- IO . puts ( "REdis write" )
52
- IO . inspect ( result )
53
- end
54
-
55
- defp read_rest_redis_cache ( key ) do
56
- % { url: url , token: token } = redis_config ( )
57
- urlsafe_key = Base . url_encode64 ( key )
58
-
59
- request =
60
- Fetch.Request . new! ( "#{ url } /get/#{ urlsafe_key } " ,
61
- headers: [ { "Authorization" , "Bearer #{ token } " } ]
62
- )
63
-
64
- response = Fetch . load! ( request )
65
-
66
- # term = :erlang.binary_to_term(response.body, [:safe])
67
- # term
68
-
69
- with body when not is_nil ( response . body ) <- response . body ,
70
- { :ok , % { "result" => value } } <- Jason . decode ( body ) do
71
- value
72
- else
73
- _ ->
74
- nil
75
- end
76
- end
77
-
78
- defp write_rest_redis_cache ( key , value ) do
79
- urlsafe_key = Base . url_encode64 ( key )
80
- body = [ "SET" , urlsafe_key , value ] |> Jason . encode_to_iodata! ( )
81
- # body = value |> Jason.encode_to_iodata!(value)
82
- # body = value
83
- # body = :erlang.term_to_iovec(value)
84
-
85
- % { url: url , token: token } = redis_config ( )
86
-
87
- request =
88
- Fetch.Request . new! ( url ,
89
- method: "POST" ,
90
- headers: [
91
- { "Authorization" , "Bearer #{ token } " } ,
92
- { "Content-Type" , "application/json" }
93
- ] ,
94
- body: body
95
- )
96
-
97
- response = Fetch . load! ( request )
42
+ IO . inspect ( result , label: "Redis write" )
98
43
end
99
44
100
45
defp run ( { :fetch_text , url } ) do
@@ -153,8 +98,8 @@ defmodule ComponentsGuide.Research.Source do
153
98
case key do
154
99
{ :fetch_text , url } ->
155
100
IO . puts ( "Writing to redis #{ url } " )
156
- # write_redis_cache(url, value)
157
- write_rest_redis_cache ( url , value )
101
+ write_redis_cache ( url , value )
102
+ # write_rest_redis_cache(url, value)
158
103
159
104
_ ->
160
105
nil
@@ -177,7 +122,7 @@ defmodule ComponentsGuide.Research.Source do
177
122
from_redis =
178
123
case key do
179
124
{ :fetch_text , url } ->
180
- if should_read_url_from_redis ( url ) , do: read_rest_redis_cache ( url ) , else: nil
125
+ if should_read_url_from_redis ( url ) , do: read_redis_cache ( url ) , else: nil
181
126
182
127
_ ->
183
128
nil
0 commit comments