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

时间:2022-01-29 23:31:30

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

我正在尝试配置我的Rack应用程序以使用Memcache与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)

在`initialize':没有memcache服务器(RuntimeError)

Heroku has put the config in environment variables

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

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

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

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

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

1 个解决方案

#1


5  

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

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

    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://github.com/mperham/dalli/commit/4ac5a99上阅读源代码后

#1


5  

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

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

    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://github.com/mperham/dalli/commit/4ac5a99上阅读源代码后