-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Evan redis #2
base: master
Are you sure you want to change the base?
Evan redis #2
Conversation
}, | ||
}; | ||
|
||
class myredis { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.class推荐以大驼峰命名
myredis这个名称不像是一个官方库,建议follow官方库的名称或直接叫'redis'
this.myRedis = Redis.createClient(this.config.client.port, this.config.client.host, | ||
{connect_timeout: this.config.client.connect_timeout} | ||
); | ||
this.myRedis.on("error", function(err) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里对于redis异常捕获后,需要提供一个钩子给调用者
console.log('redis error',err) | ||
}); | ||
|
||
this.myRedis.on('ready', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.对于connect一个redis,是异步过程,可以先返回promise,在onready里面resolve比较合理
eg:
return new Promise((resolve,reject)=>{ this.myRedis.on('ready',()=>{ resolve({ code:1, message: ''connected'' }) }) })
2.如果确实想使用现在的方式,可以对于redis的ready事件提供一个钩子
return this.myRedis; | ||
} | ||
|
||
set (key, value, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不推荐使用callback的方式进行返回,可以使用promise进行处理,方便外部使用async await
} | ||
} | ||
|
||
get (key,callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不推荐使用callback的方式进行返回,可以使用promise进行处理,方便外部使用async await
}); | ||
} | ||
|
||
setex (key, maxAge, value, callback) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不推荐使用callback的方式进行返回,可以使用promise进行处理,方便外部使用async await
@@ -0,0 +1,56 @@ | |||
let redis = require('../plugin/redis/redis'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要进行代码格式化,提高可读性,现在这样在github是不易于阅读的
欧巴 我push 了