【发布时间】:2018-01-26 14:00:50
【问题描述】:
Firebase 数据库:
{
"balance" : 10
}
应用程序 1(伪代码):
if (balance-10 >= 0)
{
// Application freezes for a few seconds. (Connection/hardware issue or whatever reason)
balance -= 10;
}
应用程序 2(伪代码):
if (balance-10 >= 0)
{
// Application is executed without any problems.
balance -= 10;
}
如果两个应用程序同时启动,最终的“余额”值将是“-10”而不是“0”。
在 MySQL 中,这个问题很容易解决:
UPDATE `table` SET balance=IF(balance-10>=0, balance-10, balance);
Firebase 有哪些可能的解决方案?
【问题讨论】:
标签: firebase firebase-realtime-database