Scott Hiett commited on
Commit
c2de526
·
1 Parent(s): db4111e

Handler now directly talks to allocated worker node, so the Client is no longer locked up by all redis commands

Browse files
lib/srh/http/command_handler.ex CHANGED
@@ -2,6 +2,7 @@ defmodule Srh.Http.CommandHandler do
2
  alias Srh.Http.RequestValidator
3
  alias Srh.Auth.TokenResolver
4
  alias Srh.Redis.Client
 
5
 
6
  def handle_command(conn, token) do
7
  case RequestValidator.validate_redis_body(conn.body_params) do
@@ -26,7 +27,8 @@ defmodule Srh.Http.CommandHandler do
26
  case GenRegistry.lookup_or_start(Client, srh_id, [max_connections, connection_info]) do
27
  {:ok, pid} ->
28
  # Run the command
29
- case Client.redis_command(pid, command_array) do
 
30
  {:ok, res} ->
31
  {:ok, %{result: res}}
32
  {:error, error} ->
 
2
  alias Srh.Http.RequestValidator
3
  alias Srh.Auth.TokenResolver
4
  alias Srh.Redis.Client
5
+ alias Srh.Redis.ClientWorker
6
 
7
  def handle_command(conn, token) do
8
  case RequestValidator.validate_redis_body(conn.body_params) do
 
27
  case GenRegistry.lookup_or_start(Client, srh_id, [max_connections, connection_info]) do
28
  {:ok, pid} ->
29
  # Run the command
30
+ case Client.find_worker(pid)
31
+ |> ClientWorker.redis_command(command_array) do
32
  {:ok, res} ->
33
  {:ok, %{result: res}}
34
  {:error, error} ->
lib/srh/redis/client.ex CHANGED
@@ -25,15 +25,15 @@ defmodule Srh.Redis.Client do
25
  }
26
  end
27
 
28
- def redis_command(client, command_array) do
29
- GenServer.call(client, {:redis_command, command_array})
30
  end
31
 
32
- def handle_call({:redis_command, command_array}, _from, %{registry_pid: registry_pid} = state)
33
  when is_pid(registry_pid) do
34
  {:ok, worker} = ClientRegistry.find_worker(registry_pid)
35
  Process.send(self(), :reset_idle_death, [])
36
- {:reply, ClientWorker.redis_command(worker, command_array), state}
37
  end
38
 
39
  def handle_call(_msg, _from, state) do
 
25
  }
26
  end
27
 
28
+ def find_worker(client) do
29
+ GenServer.call(client, {:find_worker})
30
  end
31
 
32
+ def handle_call({:find_worker}, _from, %{registry_pid: registry_pid} = state)
33
  when is_pid(registry_pid) do
34
  {:ok, worker} = ClientRegistry.find_worker(registry_pid)
35
  Process.send(self(), :reset_idle_death, [])
36
+ {:reply, worker, state}
37
  end
38
 
39
  def handle_call(_msg, _from, state) do