Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Evan redis #2

wants to merge 10 commits into from

Conversation

z-eveah
Copy link

@z-eveah z-eveah commented Dec 18, 2018

欧巴 我push 了

},
};

class myredis {
Copy link
Contributor

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) {
Copy link
Contributor

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 () {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要进行代码格式化,提高可读性,现在这样在github是不易于阅读的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants