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

feat: definition and implementation of the incrbyfloat command #67

Merged
merged 19 commits into from
Dec 10, 2023

Conversation

jettcc
Copy link
Collaborator

@jettcc jettcc commented Dec 4, 2023

#31
definition and implementation incrbyfloat command, passed local testing.
Execution result:
CleanShot 2023-12-04 at 22 57 30@2x

@github-actions github-actions bot added the ✏️ Feature New feature or request label Dec 4, 2023
int StrToLongDouble(const char* s, size_t slen, long double* ldval) {
char* pEnd;
std::string t(s, slen);
if (t.find(' ') != std::string::npos) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

感觉这里的判断应该不需要吧,你在后面已经判断了转换的pEnd是否等于字符串的长度了,这里应该冗余了

Copy link
Collaborator Author

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提示转换失败会更好

Copy link
Collaborator

Choose a reason for hiding this comment

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

其实这个参数检查的时候应该就会检查出来吧 只接受3个参数,结果传了4个参

Copy link
Collaborator Author

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 Show resolved Hide resolved
src/cmd_kv.cc Outdated Show resolved Hide resolved
AlexStocks
AlexStocks previously approved these changes Dec 9, 2023
src/cmd_kv.cc Outdated
}

void IncrbyfloatCmd::DoCmd(PClient* client) {
std::string new_value_;
Copy link
Contributor

Choose a reason for hiding this comment

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

new_value

@AlexStocks AlexStocks merged commit ad6d274 into OpenAtomFoundation:unstable Dec 10, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.1.0 core ✏️ Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants