如何指定memcache服务器到Rack :: Session :: Memcache?

Col*_*nic 2 ruby memcached rack heroku dalli

我正在尝试配置我的Rack应用程序以使用Memcache与Rack :: Session :: Memcache进行会话

如何为其提供选项(例如服务器,用户名和密码)?

现在我有

use Rack::Session::Memcache
Run Code Online (Sandbox Code Playgroud)

但是我得到了错误

在`initialize'中:没有内存缓存服务器(RuntimeError)

Heroku已将配置放在环境变量中

MEMCACHE_PASSWORD:           
MEMCACHE_SERVERS:            
MEMCACHE_USERNAME:           
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用ENV ['MEMCACHE_PASSWORD']在Ruby中获取这些内容,但我不知道如何将它们交给Rack :: Session :: Memcache

编辑:或者Rack :: Session :: Dalli也会很棒https://github.com/mperham/dalli

Col*_*nic 5

这个配置适用于Heroku,Dalli很聪明,并且知道查看环境变量

    require 'dalli'
    require 'rack/session/dalli'
    use Rack::Session::Dalli, :cache => Dalli::Client.new
Run Code Online (Sandbox Code Playgroud)

https://github.com/mperham/dalli/commit/4ac5a99上阅读源代码后