サーチ…


前書き

トランザクションは、同じデータに同時にアクセスしている可能性のある複数の関係者を調整するメカニズムを提供します。これらの「当事者」は、同じアプリケーションまたはサーバークラスタ内のノードを実行する異なるユーザー、同じプログラムまたはイベントの一部、管理アプリケーション、「エンドユーザー」アプリケーション、バックエンド "サーバーロジック。

分散カウンタ

多くのユーザーがすべてデータベースのカウンタをインクリメントしようとしているWebアプリケーションを実行しているとします。各ユーザーは、現在のカウントを読み取り、1を追加し、更新された値を書き出す必要があります。他の誰かがトランザクションを追加している間に誰もカウンタを読み取らないようにするには、トランザクションを使用します。

ref.transaction(function(value){
  if (value === null) {
    // the counter doesn't exist yet, start at one
    return 1;
  } else if (typeof value === 'number') {
    // increment - the normal case
    return value + 1;
  } else {
    // we can't increment non-numeric values
    console.log('The counter has a non-numeric value: ' + value)
    // letting the callback return undefined cancels the transaction
  }
});


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow