How to specify memcache server to Rack::Session::Memcache?

主宰稳场 提交于 2019-12-13 16:32:22

问题


I'm trying to configure my Rack app to use Memcache for sessions with Rack::Session::Memcache

How do I give it the options (such as server, username and password)?

Presently I have

use Rack::Session::Memcache

But I get the error

in `initialize': No memcache servers (RuntimeError)

Heroku has put the config in environment variables

MEMCACHE_PASSWORD:           
MEMCACHE_SERVERS:            
MEMCACHE_USERNAME:           

I know I can get these in Ruby with ENV['MEMCACHE_PASSWORD'] but I don't know how to give them to Rack::Session::Memcache

Edit: or to Rack::Session::Dalli that would be great too https://github.com/mperham/dalli


回答1:


This config worked for Heroku, Dalli is clever and knows to look in the environment variables

    require 'dalli'
    require 'rack/session/dalli'
    use Rack::Session::Dalli, :cache => Dalli::Client.new

After reading the source code at https://github.com/mperham/dalli/commit/4ac5a99



来源:https://stackoverflow.com/questions/12786976/how-to-specify-memcache-server-to-racksessionmemcache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!