如何将Memcache服务器指定为Rack :: Session :: Memcache? [英] How to specify memcache server to Rack::Session::Memcache?

查看:77
本文介绍了如何将Memcache服务器指定为Rack :: Session :: Memcache?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将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

但是我得到了错误

在初始化"中:没有内存缓存服务器(RuntimeError)

in `initialize': No memcache servers (RuntimeError)

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆