何时使用Firebase交易 [英] When to use Firebase transactions or not

查看:190
本文介绍了何时使用Firebase交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有必要使用保存数据作为交易技术,如果价值只增加?在示例Firebase文档社交博客应用程序中, starCount 可以上涨或下跌,所以使用Transaction Technic权利是合理的。但是,如果价值只会增加,我认为交易技术是不正确的?要么?
多个用户同时增加一个值。

解决方案

柜台可以长大或缩小,意味着用户可以点击计数器增加值,但如果再次点击,也可以减小该值。当我们使用交易时,我们不仅仅用来增加或减少一个计数器,如果我们知道在我们的应用程序中有两个用户可以在同一时间做同样的动作的可能性。如果我们不使用交易,如果两个用户在同一时间采取行动,那么柜台只能增加/减少一个,而不是两个。

如果我们使用事务,两个动作都会在不同的执行线程中进行,所以没有办法让一个计数器只能增加/减少一次,即使两个用户在同一时间都采取相同的动作。



总之,每当您认为可能有两个或两个以上的用户同时更改Firebase数据库中的相同值时,请使用交易。



希望有帮助。


Is it necessary to use the Save data as transactions Technic if a value only increases?. In the example Firebase doc social blogging app the starCount can go upp or down so it´s logical to use the Transaction Technic right. But if value only increases I suppose the Transaction Technic is not needed right? or? Multiple users at the same time increasing a value right.

解决方案

The counter can grow up or down, means that a user can click on the counter to increase the value, but can also decrease the value if he clicks again. When we use transactions, we don't use only to increase or decrease a counter, we use if know that in our app is a possibility that two users can make the same action in the same time. If we don't use transactions, the counter can be increased/decreased only by one, in stead of two times, if two users take the action in the same time.

If we use transactions, both actions will take place in different threads of execution, so there is no way in which a counter can be increased/decreased only once, even both users take the same action in the same time.

As a conclusion, use transactions every time you think that is a posibillity that two or more users can change the same value in your Firebase database at the same time.

Hope it helps.

这篇关于何时使用Firebase交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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