Sinatra 同步与 Redis 连接池
这是使用 Sinatra Synchrony 处理 Redis 连接池的正确方法吗?
我的 gemfile 如下所示:
gem 'sinatra-synchrony'
gem 'hiredis'
gem 'redis'
sinatra 服务器文件使用经典样式方法,通常如下所示:
require 'sinatra'
require 'sinatra/synchrony'
require 'redis/connection/hiredis'
require 'redis/connection/synchrony'
require 'redis'
redis = EventMachine::Synchrony::ConnectionPool.new(size: 5) do
Redis.new(path: '/tmp/redis.sock')
end
get / do
# lots of redis reads and writes
end
然后我启动同一服务器应用程序的多个实例,每个实例位于不同的端口下,并使用 nginx 在它们之间进行负载平衡。
这是使用 Sinatra 服务器连接 Redis 连接池的正确解决方案吗?
Is this the correct way of handling Redis connection pooling with Sinatra Synchrony?
My gemfile looks like this:
gem 'sinatra-synchrony'
gem 'hiredis'
gem 'redis'
The sinatra server files use the classic style approach, and generally look like so:
require 'sinatra'
require 'sinatra/synchrony'
require 'redis/connection/hiredis'
require 'redis/connection/synchrony'
require 'redis'
redis = EventMachine::Synchrony::ConnectionPool.new(size: 5) do
Redis.new(path: '/tmp/redis.sock')
end
get / do
# lots of redis reads and writes
end
I then launch multiple instances of the same server application, each under a different port, and use nginx to load balance between them.
Is this the proper solution for connection pooling Redis with Sinatra servers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个工作示例,我删除了 sinatra/sinatra 因为我觉得不需要它并且无法使其工作:
Gemfile:
config.ru:
并运行它(在同一文件夹中):
在真实的应用程序中您可以从 config.ru 文件中删除应用程序代码并添加一个 require,但至少它给您一个开始:)
Here is a working example, I removed sinatra/sinatra because I don't feel it is needed and I couldn't make it works:
Gemfile:
config.ru:
And run it with (in the same folder):
In a real application you would remove the application code from the config.ru file and add a require but at least it gives you a start :)