-
Notifications
You must be signed in to change notification settings - Fork 63
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
feat: definition and implementation of the incrbyfloat command #67
Conversation
int StrToLongDouble(const char* s, size_t slen, long double* ldval) { | ||
char* pEnd; | ||
std::string t(s, slen); | ||
if (t.find(' ') != std::string::npos) { |
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.
感觉这里的判断应该不需要吧,你在后面已经判断了转换的pEnd是否等于字符串的长度了,这里应该冗余了
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.
我觉得还是留着比较好,因为我看了strtold
这个函数,它可能会在遇到空格时停止转换,并返回到目前为止已经转换的数字,比如1 23.45
就会变成1.0
,我并不希望发生这样的事情。
举个例子,我在执行incrbyfloat test 123.45
的时候因为某些原因输入成了incrbyfloat test 12 3.45
,这时候test
会增加12.0
, 不能达到命令的预期,所以我觉得这里也是个防呆操作,只要字符串含有空格就直接抛出-1
提示转换失败会更好
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.
其实这个参数检查的时候应该就会检查出来吧 只接受3个参数,结果传了4个参
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.
但是我觉得这个是公共方法,不是只有incrbyfloat
这一个命令用到,我觉得严谨一点会更好
src/cmd_kv.cc
Outdated
} | ||
|
||
void IncrbyfloatCmd::DoCmd(PClient* client) { | ||
std::string new_value_; |
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.
new_value
#31
definition and implementation
incrbyfloat
command, passed local testing.Execution result: