通过“firebase”和“gcloud”启动firestore emulator之间的区别?

2024-05-14 12:03:28 发布

您现在位置:Python中文网/ 问答频道 /正文

通过以下方式启动firestore emulator有什么区别:

firebase emulators:start --only firestore

以及:

gcloud beta emulators firestore start

这两个选项都允许我的python应用程序实现与数据库的连接,如下所示:

import google
from google.cloud import firestore

os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8081"
os.environ["FIRESTORE_EMULATOR_HOST_PATH"] = "localhost:8081/firestore"
os.environ["FIRESTORE_HOST"] = "http://localhost:8081"

credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = firestore.Client(credentials=credentials)

我自己注意到的一个区别是firebase似乎尊重我的firebase.json,特别是这样指定的主机端口:

{
  "emulators": {
    "firestore": {
      "port": "8081"
    }
  }
}

另一方面,gcloud忽略firebase.json,而是选择一个随机端口,除非我显式地通过--host-port传递端口。这是两者之间更大区别的一部分吗?还有什么其他区别


Tags: 端口importlocalhosthostosgoogleenvironstart
1条回答
网友
1楼 · 发布于 2024-05-14 12:03:28

我一直在看这两个工具的文档,它们做的事情几乎相同

使用Firebase tool可以启动多个Firebase产品的模拟器,而gcloud command允许启动GCP模拟器。Firestore只是他们共同拥有的一种产品,因此他们的效用应该相同或相似

关于功能差异,firebase提供了 import export-on-exit标志,允许您在模拟会话之间保存和恢复数据。它还提供了一种可视化security rules如何处理当前查询的方法

除了这些功能外,我还要注意设置端口和规则文件的不同方法:

  • firebase emulators使用^{}文件
  • gcloud beta emulators使用标志^{}^{}来实现相同的功能

请注意,GCP上的Firestore emulator位于beta stage上,因此其官方支持可能有限,可能会发生更改。还请注意,在GCP's Firestore documentation上,Firebase CLI是如何代替gcloud使用的

最后,您应该使用首选工具,因为它们都朝着模拟Firestore的相同目标工作。如果您已经在使用Firebase CLI,我建议您继续使用它;如果您正在使用gcloud,请使用该选项

相关问题 更多 >

    热门问题