如题?
回复 (14)
S
S
引用 skipifyhttps://github.com/broofa/node uuid ?
@skipify 看起来太长了,有其他的选择吗
H
我想问为什么要自己去生成呢,为什么不用数据库的自增呢,这是出于安全考虑吗
Y
引用 snowdream@skipify 看起来太长了,有其他的选择吗
@snowdream 太长?不是很理解,你其实要的是随机的类md5,但是可以指定长度?
A
场景是什么?
S
引用 alsotang场景是什么?
@alsotang 作为用户id,组id
S
我现在用passport.js方案,想在用户表中插入uid,gid字段
J
有个叫 shortid 的模块, 特点是短
S
感谢以上答复,准备使用以下模块》 https://github.com/mariodu/mongoose-id-autoinc
X
function guidGenerator() {
var S4 = function() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
return (S4() + S4() + S4() + S4() + S4() + S4() + S4() + S4());
}
V
https://github.com/vczero/OurTimes/blob/master/server/util/guid.js /**
- guid模块提供生成唯一值ID,用于token生成等。如果加上objID或者用户唯一标识更好
- @module guid */ module.exports = { create: function() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }).toUpperCase(); } };
V
module.exports = {
create: function() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
}).toUpperCase();
}
};
S
感谢.选择了递增整数来做uid。
P
Redis 键值对里想做确保唯一性,用UUID,还是用Redis里面用 incr 叠加生成个ID ?
参与回复
登录后即可参与回复。登录