我目前在运行 phoenix 服务器应用程序时遇到问题。当我尝试访问 'localhost:4000' 时显示此错误。它抱怨它在运行时找不到 memcached proc,如下所示。
[error] #PID<0.558.0> running MyApp.Endpoint terminated Server: localhost:4000 (http) Request: GET /
** (exit) an exception was raised:
** (RuntimeError) cannot find memcached proc
(plug_session_memcached) lib/plug_session_memcached.ex:130: Plug.Session.MEMCACHED.get/3
(plug) lib/plug/session.ex:74: anonymous fn/5 in Plug.Session.fetch_session/1
(plug) lib/plug/debugger.ex:211: Plug.Debugger.maybe_fetch_session/1
(plug) lib/plug/debugger.ex:174: Plug.Debugger.render/6
(plug) lib/plug/debugger.ex:153: Plug.Debugger.__catch__/5
(myapp) lib/myapp/endpoint.ex:1: MyApp.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
这是我的依赖项:-
{:coherence, "~> 0.3"},
{:comeonin, "~> 2.4"},
{:cowboy, "~> 1.0"},
{:excoveralls, "~> 0.5", only: :test},
{:gettext, "~> 0.11"},
{:httpoison, "~> 0.10.0"},
{:lager, github: "basho/lager", tag: "3.2.4", override: true},
{:mailgun, "~> 0.1.2"},
{:mariaex, ">= 0.0.0"},
{:mcd, github: "EchoTeam/mcd"},
{:phoenix, "~> 1.2.1"},
{:phoenix_ecto, "~> 3.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:phoenix_pubsub, "~> 1.0"},
{:plug_session_memcached, github: "gutschilla/plug-session-memcached"},
{:timex, "~> 2.2.1"},
{:timex_ecto, "~> 1.1.3"}
这很可能是我在 endpoint.ex 中的 Plug.Session memcached 设置的问题,因为当我切换到使用 :cookies 作为我的存储时,它按预期工作,但不适用于 :memcached。任何帮助将不胜感激。
这是它在 Plug.Session.MEMCACHED 中引发参数错误的代码
@max_tries 100
def init(opts) do
Keyword.fetch!(opts, :table)
end
def get( conn, sid, table) do
case :mcd.get( table, sid ) do
{:error, :noproc} -> raise ArgumentError, "cannot find memcached proc"
{:error, :notfound} -> {nil, %{}}
{:error, :noconn} -> {nil, %{}}
{:ok, data } -> {sid, data}
end
end
def put( _conn, nil, data, table) do
put_new(data, table)
end
def put( _conn, sid, data, table) do
:mcd.set( table, sid, data )
sid
end
def delete( _conn, sid, table) do
:mcd.delete(table, sid)
:ok
end
defp put_new(data, table, counter \\ 0)
when counter < @max_tries do
sid = :crypto.strong_rand_bytes(96) |> Base.encode64
put( nil, sid, data, table )
end