Firestore产生两个相同的随机密钥的机会是什么? [英] What are the chances for firestore to generate two identical random keys?

查看:47
本文介绍了Firestore产生两个相同的随机密钥的机会是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个项目和firestore随机密钥,在这种情况下,这很重要,所以我的问题是,firebase firestore或实时数据库生成两个或多个相同随机变量的机会是多少?

I am working on a project and firestore random keys where kind of important in this scenario, so my question is, what are the chances for firebase firestore or the real-time database to generate two or more identical random variables?

推荐答案

尽管GastónSaillén对于Firebase实时数据库中的推入键的回答是100%正确,但我将尝试添加更多详细信息.

While Gastón Saillén's answer is 100% correct regarding the pushed key from Firebase realtime database, I'll try to add a few more details.

使用DatabaseReference的 push()方法,它生成具有时间成分的密钥,因此理论上基本上可以在同一毫秒内发生两个事件,但是从天文学角度来看,两个用户可以在完全相同的时刻生成密钥的可能性很小并具有完全相同的随机性另请注意,这些密钥完全在客户端上生成,无需咨询Firebase服务器.如果您有兴趣,请参见生成这些密钥的算法.最后,我可以告诉您,到目前为止,我还没有听说过有人报告按键碰撞问题.

When using DatabaseReference's push() method, it generates a key that has a time component, so basically two events can theoretically take place within the same millisecond but there is an astronomically small chance that two users can generate a key in the exact same moment and with the exact same randomness. Please also note, that these keys are generated entirely on the client without consultation Firebase server. If you are interested, here is the algorithm that generates those keys. In the end, I can tell you that I haven't heard of a person who reported a problem with key collisions so far.

因此,与Fireabase实时数据库密钥不同,Cloud Firestore ID实际上是纯粹随机的.没有时间组件.当您调用CollectionReference的帖子中查看Frank van Puffelen的答案.因此,您不必担心此ID.

So unlike Fireabase realtime database keys, Cloud Firestore ids are actually purely random. There's no time component included. This built-in generator for unique ids that is used in Firestore when you call CollectionReference's add() methods or CollectionReference's document() method without passing any parameters, generates random and highly unpredictable ids, which prevents hitting certain hotspots in the backend infrastructure. That's also the reason why there is no order, if you check the documents in a collection in the Firebase console. The collisions of ids in this case is incredibly unlikely and you can/should assume they'll be completely unique. That's what they were designed for. Regarding the algorithm, you can check Frank van Puffelen's answer from this post. So you don't have to be concerned about this ids.

这篇关于Firestore产生两个相同的随机密钥的机会是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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