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

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





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 のサンプルをご覧ください。