Firebase 推送唯一性范围
Firebase push uniqueness scope
文档说 Firebase 推送生成一个唯一的密钥,我想知道这个密钥在我的整个数据库(甚至是 GuId)中是否唯一,或者只是在它被推送到的节点中是唯一的
我正在像这样构建我的数据库(根据他们的指南,我把它压平了):
users {
-KIH-uFo_2jW16Ue8JNH { //User-Key
username : "Johnny Dummy"
gender : "male"
}
}
items {
-KIH-uFo_2jW16Ue8JNH { //User-Key
-KIH6iaw5uAS856i6-u9 : { //Item-Key
itemname : "Item Dummy"
count : 3
}
}
}
因此,当我获取所有用户的所有项目时,Item-Key 的唯一性范围对我很重要
它在整个数据库中是唯一的。来自文档:
Generate a new child location using a unique name and returns a Firebase reference to it. This is useful when the children of a
database location represent a collection of items. See Saving Lists of
Data.
You can optionally pass a value to push() and the value will be
immediately written to the generated location. If you don't pass a
value to push(), nothing is written and the child will remain empty
unless written to using set().
The unique name generated by push() is prefixed with a
client-generated timestamp so that the resulting list will be
chronologically-sorted.
统计上几乎不可能获得重复的推送 ID。为此:
- id的前48位,客户端生成的时间戳,需要在同一毫秒内生成
- 接下来的 72 个随机生成的位需要相同。所以你可以有重复的推送 ID,但是有 2^72 种可能的随机排列(超过 4 六十亿,是世界上所有海滩上估计的沙粒的 4 倍)。所以你会在同一毫秒内需要很多推送请求。
核心开发人员之一写了一篇博客 post 描述了它们是如何生成的:https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
"A push ID contains 120 bits of information. The first 48 bits are a timestamp, which both reduces the chance of collision and allows consecutively created push IDs to sort chronologically. The timestamp is followed by 72 bits of randomness, which ensures that even two people creating push IDs at the exact same millisecond are extremely unlikely to generate identical IDs. One caveat to the randomness is that in order to preserve chronological ordering if a client creates multiple push IDs in the same millisecond, we just 'increment' the random bits by one."
文档说 Firebase 推送生成一个唯一的密钥,我想知道这个密钥在我的整个数据库(甚至是 GuId)中是否唯一,或者只是在它被推送到的节点中是唯一的
我正在像这样构建我的数据库(根据他们的指南,我把它压平了):
users {
-KIH-uFo_2jW16Ue8JNH { //User-Key
username : "Johnny Dummy"
gender : "male"
}
}
items {
-KIH-uFo_2jW16Ue8JNH { //User-Key
-KIH6iaw5uAS856i6-u9 : { //Item-Key
itemname : "Item Dummy"
count : 3
}
}
}
因此,当我获取所有用户的所有项目时,Item-Key 的唯一性范围对我很重要
它在整个数据库中是唯一的。来自文档:
Generate a new child location using a unique name and returns a Firebase reference to it. This is useful when the children of a database location represent a collection of items. See Saving Lists of Data.
You can optionally pass a value to push() and the value will be immediately written to the generated location. If you don't pass a value to push(), nothing is written and the child will remain empty unless written to using set().
The unique name generated by push() is prefixed with a client-generated timestamp so that the resulting list will be chronologically-sorted.
统计上几乎不可能获得重复的推送 ID。为此:
- id的前48位,客户端生成的时间戳,需要在同一毫秒内生成
- 接下来的 72 个随机生成的位需要相同。所以你可以有重复的推送 ID,但是有 2^72 种可能的随机排列(超过 4 六十亿,是世界上所有海滩上估计的沙粒的 4 倍)。所以你会在同一毫秒内需要很多推送请求。
核心开发人员之一写了一篇博客 post 描述了它们是如何生成的:https://firebase.googleblog.com/2015/02/the-2120-ways-to-ensure-unique_68.html
"A push ID contains 120 bits of information. The first 48 bits are a timestamp, which both reduces the chance of collision and allows consecutively created push IDs to sort chronologically. The timestamp is followed by 72 bits of randomness, which ensures that even two people creating push IDs at the exact same millisecond are extremely unlikely to generate identical IDs. One caveat to the randomness is that in order to preserve chronological ordering if a client creates multiple push IDs in the same millisecond, we just 'increment' the random bits by one."