elixir - Process.register Not Applying to Atom -
i trying make atom database connection redis. use name
option in start
of genserver
, not available. in getting started (elixir 1.0.5), example seems show process.register(pid, :kv)
option. maybe there better option make process accessible?
following showing how doesn't match guard in query connection client.
iex(2)> redis_client = exredis.start #pid<0.367.0> iex(3)> process.register(redis_client, :redis_client) true iex(4)> :redis_client |> exredis.query ["get", "test"] ** (functionclauseerror) no function clause matching in exredis.query/2 (exredis) lib/exredis.ex:95: exredis.query(:redis_client, ["get", "test"]) iex(4)> redis_client |> exredis.query ["get", "test"] :undefined iex(5)> redis_client |> exredis.query ["set", "test", "value"] "ok" iex(6)> redis_client |> exredis.query ["get", "test"] "value" iex(7)> :redis_client :redis_client
your error comes these lines in exredis' source:
def query(client, command) when is_pid(client) , is_list(command), do: client |> :eredis.q(command) |> elem(1)
as can see, start_link/2
accepts pid first argument (when is_pid(client)
).
you can use process.whereis/1
find pid of registered process , pass exredis:
iex> :redis_client |> process.whereis |> exredis.query(["set", "test", "value"]) "ok"
Comments
Post a Comment