nodejs 对象保存redis 去除propotype
来源:互联网 发布:linux terminal 命令 编辑:程序博客网 时间:2024/06/05 11:24
node.js 实践 user保存redis 会保存propotype方法,改变方法定义方式,可避免propotype持久化到redis
function User(obj) { for (var key in obj) { this[key] = obj[key]; console.log(obj[key]); } this.save = function (fn) { if (this.id) { this.update(fn); } else { var user = this; debugger db.incr("user:ids", function (err, id) { if (err) { return fn(err); } debugger user.id = id; user.hashPassword(function (err) { if (err) { return fn(err); } debugger user.update(fn); }) }) } } this.hashPassword=function (fn) { var user = this; bcrypt.genSalt(12, function (err, salt) { if (err) { return fn(err); } user.pass = salt; fn(); }) } this.update=function (fn) { var user = this; var id = user.id; db.set('user:id:' + user.name, id, function (err) { if (err) { return fn(err); } db.hmset('user:' + id, user, function (err) { fn(err); }) }) } Object.defineProperty(this, "save", { enumerable: false }) Object.defineProperty(this, "update", { enumerable: false }) Object.defineProperty(this, "hashPassword", { enumerable: false })}
阅读全文
0 0
- nodejs 对象保存redis 去除propotype
- redis 保存对象
- redis 保存对象方法
- Redis保存对象实例
- redis保存对象
- Redis无法保存ef复杂对象
- nodejs 保存数组/对象,对其进行处理,而不影响原数组/对象
- 【redis,1】java操作redis: 将string、list、map、自定义的对象保存到redis中
- java鬼混笔记:springboot之redis保存对象
- nodejs保存文件问题
- nodejs - redis操作例程
- nodejs express session redis
- Nodejs 操作redis数据库
- nodejs 操作redis
- redis lua and nodejs
- nodejs redis commands
- nodejs连接redis
- nodejs远程连接redis
- Java与c++不同的地方
- Input.GetMouseButtonDown()方法 &Input.GetMouseButton()方法
- 在eclipse,Hbuilder中使用svn
- 关于Grid内嵌控件:ReporisitoryItemLookUpEdit的使用
- VR技术推动学生的深度学习还真不是“扯淡”
- nodejs 对象保存redis 去除propotype
- App启动画面问题
- QT 生成EXE执行文件
- 51 nod 最高奖励(贪心+优先队列)
- android 悬浮通知
- mysql树形查询语句
- PullToFreshListView
- RAID常用级别的比较
- header("Content-type:text/html;charset=gb2312")所引起的POST接收乱码