Sinatra Synchrony与Redis连接池(Sinatra Synchrony with Redis connection pooling)
这是处理与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在它们之间进行负载平衡。
这是Redis与Sinatra服务器连接池的正确解决方案吗?
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?
原文:https://stackoverflow.com/questions/8856001
最满意答案
语法明智这是不正确的。
问题在这里得到解决:
CREATE TABLE Venue ( venueID VARCHAR(20), venueEmail VARCHAR(30) NOT NULL, address VARCHAR(100), phoneNo VARCHAR(20), managerNo VARCHAR(20), capacity INT(4), PRIMARY KEY (venueEmail) )ENGINE=InnoDB; CREATE TABLE Concert ( referenceNo VARCaHAR(6), venueEmail VARCHAR(30), eventDate VARCHAR(10), startTime VARCHAR(5), ticketsSold INT(4), PRIMARY KEY (referenceNo), FOREIGN KEY (venueEmail) REFERENCES Venue(`venueEmail`) ON UPDATE CASCADE ON DELETE CASCADE )ENGINE=InnoDB;
注意:
引用的列应该类似于
table_name(column_name)
。你错过了
column_name
部分。
更多:
@Bill Karwin在评论部分添加了以下有用信息:
FWIW这是一个MySQL的特质。 在标准SQL中,如果省略引用的列名,则默认使用与外键列相同的名称。 但InnoDB不支持此快捷方式语法 - 您必须在两种情况下都指定列。
Syntax wise this isn't correct.
The issue's resolved here:
CREATE TABLE Venue ( venueID VARCHAR(20), venueEmail VARCHAR(30) NOT NULL, address VARCHAR(100), phoneNo VARCHAR(20), managerNo VARCHAR(20), capacity INT(4), PRIMARY KEY (venueEmail) )ENGINE=InnoDB; CREATE TABLE Concert ( referenceNo VARCaHAR(6), venueEmail VARCHAR(30), eventDate VARCHAR(10), startTime VARCHAR(5), ticketsSold INT(4), PRIMARY KEY (referenceNo), FOREIGN KEY (venueEmail) REFERENCES Venue(`venueEmail`) ON UPDATE CASCADE ON DELETE CASCADE )ENGINE=InnoDB;
Note:
The column being referenced should be stated like
table_name(column_name)
.You missed the
column_name
part.
More:
@Bill Karwin added the following useful info in the comment section:
FWIW this is a MySQL idiosyncrasy. In standard SQL, if you omit the referenced column name, it defaults to the same name as the foreign key column. But InnoDB doesn't support this shortcut syntax—you must specify the column in both cases.
相关问答
更多-
我猜测Clients.Case_Number和/或Staff.Emp_ID与Clients_has_Staff.Clients_Case_Number和Clients_has_Staff.Staff_Emp_ID不完全相同的数据类型。 父表格中的列也许是INT UNSIGNED ? 他们需要在两个表中都是完全相同的数据类型。 I'm guessing that Clients.Case_Number and/or Staff.Emp_ID are not exactly the same data type ...
-
不应该这样: FOREIGN KEY(pid) REFERENCES People(pid) FOREIGN KEY (eid) REFERENCES Events(eid) shouldn't it go like this : FOREIGN KEY(pid) REFERENCES People(pid) FOREIGN KEY (eid) REFERENCES Events(eid)
-
数据类型必须匹配,并且也是SIGN 。 如果未指定UNSIGNED ,则签名。 如另一个答案中提到的那样,使用foreign_key_checks ,我会做最后一件事。 人们经常忘记他们做到了,并猜测问题出现在哪里:Stackoverflow。 以下将有效: 创建测试平台: create schema Monday001a; use Monday001a; 脚本: drop table if exists areas; drop table if exists roles; drop table if e ...
-
在外键可以引用该列之前,您需要cognome_candidato的索引。 You need an index for cognome_candidato, before a foreign key can reference that column.
-
这是因为忠诚度积分中的总点数并不是唯一的。 我通过更改loyalypoints表添加到: CREATE TABLE loyaltypoints (voucherid int(10) AUTO_INCREMENT PRIMARY KEY, totalpoints int(5) UNIQUE); 通常外键是指另一个表的主键。 你还有游戏代码为int(5),gameid为int(10)。 当我运行它时没有引起错误,但它们应该是相同的长度。 It's because totalpoints in loyaltyp ...
-
您的查询显示您错误地放置了列和表格: Schema::table('subtags', function (Blueprint $table) { $table->foreign('tag_id') ->references('tags') ->on('id') ->onDelete('cascade'); $table->primary(array('tag_id', 'id')); }); 参考应该是“ 表 ” 上的 “ 列 ...
-
尽管Tim的答案是正确的,但我建议你在Entry条目表中不要有subject_name列。 你可以随时从主题表中获得它。 但是,如果您想要在Entries表中保留subjects_name列,并且想要在subject_name列上添加FOREIGN键约束,则可以在subject表中将subject_name声明为唯一列 alter table `subjects` add unique (`subject_name`); 或在主题表中的subject_name列上创建索引。 alter table `su ...
-
事实证明我的外键约束都搞砸了。 我的关系倒退了。 我没有让外键引用主键,而是让主键是引用非唯一列的外键。 我扭转了这一点,并且它奏效了。 So it turns out my foreign key constraints were all messed up. I had the relationships backwards. Instead of having the foreign keys reference the primary keys, I was having the primary k ...
-
语法明智这是不正确的。 问题在这里得到解决: CREATE TABLE Venue ( venueID VARCHAR(20), venueEmail VARCHAR(30) NOT NULL, address VARCHAR(100), phoneNo VARCHAR(20), managerNo VARCHAR(20), capacity INT(4), PRIMARY KEY (venueEmail) )ENGINE=I ...
-
你说ON DELETE SET NULL但是这两个字段都不可为空。 请尝试ON DELETE CASCADE 。 您还可以检查以确保两个表都使用InnoDB引擎。 You're saying ON DELETE SET NULL but both of the fields in question are not nullable. Try ON DELETE CASCADE instead. You can also check to make sure both tables are using the ...