Session ';找不到memcached proc';在Elixir中运行Phoenix应用程序时出错
我目前在运行phoenix服务器应用程序时遇到问题。当我尝试访问“localhost:4000”时,会显示此错误。它抱怨在运行时找不到memcached proc,如下所示Session ';找不到memcached proc';在Elixir中运行Phoenix应用程序时出错,session,memcached,elixir,phoenix-framework,plug,Session,Memcached,Elixir,Phoenix Framework,Plug,我目前在运行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) can
[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
这很可能是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
@max\u尝试100次
def初始化(选项)do
关键字:fetch!(选项:表格)
结束
def get(连接、sid、表格)do
案例:mcd.get(表格,sid)do
{:error,:noproc}->raiseargumenterror,“找不到memcached进程”
{:错误,:notfound}->{nil,%{}
{:错误,:noconn}->{nil,%{}
{:好的,数据}->{sid,数据}
结束
结束
def put(_conn,nil,data,table)do
新建(数据、表格)
结束
def put(_conn,sid,数据,表格)do
:mcd.set(表格、sid、数据)
希德
结束
def delete(_conn,sid,table)do
:mcd.delete(表,sid)
:好的
结束
defp put_new(数据、表格、计数器\\0)
当计数器<@max\u尝试执行时
sid=:crypto.strong_rand_bytes(96)|>Base.encode64
put(无、sid、数据、表格)
结束
您没有启动插件会话\u memcached
或其依赖项
像这样调整你的mix.exs
(引自)
def应用程序
[
...
应用程序:[
...
:lager,:corman#您是否遵循了plug session memcached自述文件中的所有说明(特别是向应用程序/0
中添加了这些内容):?是的,所有内容都已添加。尝试从memcached表中获取sid时出现问题,我不确定原因
@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
def application do
[
...
applications: [
...
:lager, :corman # <-- add these both (mcd needs them)
],
included_applications: [
:plug_session_memcached # <--- add this entry
]
]
end