Firestore 分散カウンタのカスタム シャードとカウンタタイプを作成する

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

Firestore 分散カウンタのカスタム シャードとカウンタタイプを作成する





/// <summary>
/// Shard is a document that contains the count.
/// </summary>
public class Shard
    [FirestoreProperty(name: "count")]
    public int Count { get; set; }


import (


// Counter is a collection of documents (shards)
// to realize counter with high frequency.
type Counter struct {
	numShards int

// Shard is a single counter, which is used in a group
// of other shards within Counter.
type Shard struct {
	Count int


import random

from import firestore

class Shard(object):
    A shard is a distributed counter. Each shard can support being incremented
    once per second. Multiple shards are needed within a Counter to allow
    more frequent incrementing.

    def __init__(self):
        self._count = 0

    def to_dict(self):
        return {"count": self._count}

class Counter(object):
    A counter stores a collection of shards which are
    summed to return a total count. This allows for more
    frequent incrementing than a single document.

    def __init__(self, num_shards):
        self._num_shards = num_shards


他の Google Cloud プロダクトに関連するコードサンプルの検索およびフィルタ検索を行うには、Google Cloud のサンプルをご覧ください。