在Elixir中运行Phoenix应用程序时出现“无法找到memcached proc”错误

时间:2017-01-18 03:50:49

标签: session memcached elixir phoenix-framework plug

我目前在运行凤凰服务器应用程序时遇到问题。当我尝试访问“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

1 个答案:

答案 0 :(得分:0)

您没有启动mix.exs或其依赖项。

像这样调整def application do [ ... applications: [ ... :lager, :corman # <-- add these both (mcd needs them) ], included_applications: [ :plug_session_memcached # <--- add this entry ] ] end (来自README

PropertiesService