Ruby on Rails ActiveRecordStore 是否可以跨服务器进行负载平衡? [英] Does Ruby on Rails ActiveRecordStore work with load balancing across servers?

查看:46
本文介绍了Ruby on Rails ActiveRecordStore 是否可以跨服务器进行负载平衡?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在使用 pfsense 测试负载平衡,我正在研究如果用户连接到的原始服务器出现故障,rails 会话会发生什么.有没有办法在服务器之间同步 ActiveRecordStore 数据,或者像 SQLSessionStore 这样的东西是最好的选择?

We are currently testing load balancing with pfsense and I am looking at what will happen to a rails session if the original server a user is connected to goes down. Is there a way to sync ActiveRecordStore data between servers or would something like SQLSessionStore be the best bet?

推荐答案

是的,Ruby on Rails 支持多个 SessionStore 后端,默认情况下它使用基于 cookie 的后端.但如果您愿意,您也可以将会话保留在您的数据库中.

Yes, Ruby on Rails supports multiple SessionStore backends, by default it uses a cookie-based one. But you can also keep the session in your database if you like.

相关文档在这里:http://api.rubyonrails.org/classes/ActiveRecord/SessionStore.html

在您设置用作 SessionStore 的 ActiveRecord 模型后,您可以通过以下方式将 Rails 应用程序配置为不同的 SessionStore:

After you have set up a ActiveRecord model to be used as SessionStore you then configure your rails app to a different SessionStore through:

config.action_controller.session_store = :active_record_store

我必须承认到目前为止我还没有在我的任何项目中尝试过这个,但是你应该可以通过尝试来弄清楚:)

I have to admit that I haven't tried this out in any of my projects so far, but you should be able to figure it out by trying it out :)

这篇关于Ruby on Rails ActiveRecordStore 是否可以跨服务器进行负载平衡?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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