我应该担心 UUID 的唯一性吗
Should I worry about UUID uniqueness
我正在使用这个 https://www.npmjs.com/package/uuidv4 模块来识别用户的唯一性。我应该担心 2 个人可能会得到相同的 uuid 吗?如果我存储了当天所有给定的 uuid 并且在我提供新的 uuid 之前我检查它是否已经存在于数据库中怎么办?然后一天后我会清空我的数据库并重复这个过程。这是一个好方法吗?我错过了什么吗?
Should I worry that 2 people might get the same uuid...
不,你不应该。 UUID 是唯一的 实用 目的。
..., the number of random version 4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion...
至于:
What if I store of all given uuids for the day and before I give new uuids I check if it already exists in the database
您的 table 应该有一个 Unique Key 约束。即使您确实发生了碰撞,数据库也会拒绝它。
是的,你应该(我们也应该)。通过遵循标准程序,可以获得非常独特的 UUID。但是恶意玩家可能会故意造成冲突,因为没有 UUID 的中央注册中心。所以,现在,格外小心 UUID 不会有什么坏处。
我正在使用这个 https://www.npmjs.com/package/uuidv4 模块来识别用户的唯一性。我应该担心 2 个人可能会得到相同的 uuid 吗?如果我存储了当天所有给定的 uuid 并且在我提供新的 uuid 之前我检查它是否已经存在于数据库中怎么办?然后一天后我会清空我的数据库并重复这个过程。这是一个好方法吗?我错过了什么吗?
Should I worry that 2 people might get the same uuid...
不,你不应该。 UUID 是唯一的 实用 目的。
..., the number of random version 4 UUIDs which need to be generated in order to have a 50% probability of at least one collision is 2.71 quintillion...
至于:
What if I store of all given uuids for the day and before I give new uuids I check if it already exists in the database
您的 table 应该有一个 Unique Key 约束。即使您确实发生了碰撞,数据库也会拒绝它。
是的,你应该(我们也应该)。通过遵循标准程序,可以获得非常独特的 UUID。但是恶意玩家可能会故意造成冲突,因为没有 UUID 的中央注册中心。所以,现在,格外小心 UUID 不会有什么坏处。