Replies: 1 comment 5 replies
-
你有几个从库,试试这样: new FreeSqlBuilder()
....
.UseConnectionString(DataType.MySql, master_connectionstring)
.UseSlave(master_connectionstring, slave1_connectionstring) //把 master 也当成一个 slave
.UseSlaveWeight(100, 0)
.Build(); |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
因为主从同步存在延时,很多场景写完之后需要立即查询结果,如果查从库,主从同步出现延时会导致数据不一致。
也许你可以说直接用:_freeSql.Select().Master()。这里存在一个问题,主库不可用直接报异常,而不会自动切换从库。
在实际使用过程中也发现,在同一个事务中的查询,也不是查主库。
所以,我的需求是,freesql是否有这样的api或者配置,每次查询优先使用主库,主库不可用时用从库查。目前我的实现方式如下(感觉很别扭):
public ISelect SelectFsql() where T : BaseEntity
{
// 因为Freesql是被动触发IsAvailable
// 即使IsAvailable=true也非真的true,需要查一次
if (_freeSql.Ado.MasterPool.IsAvailable)
_freeSql.Ado.ExecuteConnectTest(1);
}
Beta Was this translation helpful? Give feedback.
All reactions