问题描述
我正在尝试将Rack应用配置为使用Memcache进行与Rack :: Session :: Memcache的会话
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)?
我现在有
use Rack::Session::Memcache
但是我得到了错误
Heroku已将配置放入环境变量中
Heroku has put the config in environment variables
MEMCACHE_PASSWORD:
MEMCACHE_SERVERS:
MEMCACHE_USERNAME:
我知道我可以使用ENV ['MEMCACHE_PASSWORD']在Ruby中获得这些,但是我不知道如何将它们提供给Rack :: Session :: Memcache
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
编辑:或也可以使用Rack :: Session :: Dalli https ://github.com/mperham/dalli
Edit: or to Rack::Session::Dalli that would be great too https://github.com/mperham/dalli
推荐答案
此配置适用于Heroku,Dalli很聪明,并且知道可以查看环境变量
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
在 https://github.com/mperham/dalli/commit/阅读源代码之后4ac5a99
这篇关于如何将Memcache服务器指定为Rack :: Session :: Memcache?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!