@@ -3,7 +3,7 @@ defmodule Srh.Redis.Client do
33 alias Srh.Redis.ClientRegistry
44 alias Srh.Redis.ClientWorker
55
6- @ idle_death_time 1000 * 15
6+ @ idle_death_time 1000 * 60 * 15 # 15 minutes
77
88 def start_link ( max_connections , connection_info ) do
99 GenServer . start_link ( __MODULE__ , { max_connections , connection_info } , [ ] )
@@ -35,6 +35,10 @@ defmodule Srh.Redis.Client do
3535 GenServer . cast ( client , { :return_worker , pid } )
3636 end
3737
38+ def destroy_workers ( client ) do
39+ GenServer . cast ( client , { :destroy_workers } )
40+ end
41+
3842 def handle_call ( { :find_worker } , _from , % { registry_pid: registry_pid } = state )
3943 when is_pid ( registry_pid ) do
4044 { :ok , worker } = ClientRegistry . find_worker ( registry_pid )
@@ -59,13 +63,17 @@ defmodule Srh.Redis.Client do
5963 { :noreply , state }
6064 end
6165
66+ def handle_cast ( { :destroy_workers } , state ) do
67+ ClientRegistry . destroy_workers ( state . registry_pid )
68+ { :stop , :normal , state }
69+ end
70+
6271 def handle_cast ( _msg , state ) do
6372 { :noreply , state }
6473 end
6574
6675 def handle_info ( :idle_death , state ) do
6776 ClientRegistry . destroy_workers ( state . registry_pid )
68-
6977 { :stop , :normal , state }
7078 end
7179
0 commit comments