-
Notifications
You must be signed in to change notification settings - Fork 592
feat(cmd): add iso8601 time format parameter to LASTSAVE command #2822
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
Conversation
src/commands/cmd_server.cc
Outdated
| return {Status::RedisParseErr, "unknown extra subcommand"}; | ||
| } | ||
| if (args.size() == 2) { | ||
| std::string fmt_arg = args[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.
You can try to use EqualICase (common->string_util.h).
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.
You can try to use
EqualICase(common->string_util.h).
Initially i came across parser.EatEqICase() but then i dropped the idea as i didnt know its correct usage so i though i'll take some feedback on its usage.
Thanks for the review i'll use EqualICase as it seems a better fit in this case.
PragmaTwice
left a comment
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.
It doesn't seem to be a Redis feature. So I'm wondering if it will be useful in production envs?
You're right this isn't a redis feature. But instead of converting the UNIX timestamp manually, users can directly retrieve an easily interpretable format. |
I've checked the issue you opened. I'm fine with this change. |
src/commands/cmd_server.cc
Outdated
| public: | ||
| Status Parse(const std::vector<std::string> &args) override { | ||
| if (args.size() > 2) { | ||
| return {Status::RedisParseErr, "unknown extra subcommand"}; |
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.
| return {Status::RedisParseErr, "unknown extra subcommand"}; | |
| return {Status::RedisParseErr, "unknown extra arguments"}; |
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.
Thanks for review, i was just working on the changes requested by torwig right now, ill make this change as well.
src/commands/cmd_server.cc
Outdated
| if (fmt_arg == "iso8601") { | ||
| format_spec_ = true; | ||
| } else { | ||
| return {Status::RedisParseErr, "unknown subcommand"}; |
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.
| return {Status::RedisParseErr, "unknown subcommand"}; | |
| return {Status::RedisParseErr, "unknown arguments"}; |
src/commands/cmd_server.cc
Outdated
| std::string fmt_arg = args[1]; | ||
| std::transform(fmt_arg.begin(), fmt_arg.end(), fmt_arg.begin(), ::tolower); | ||
| if (fmt_arg == "iso8601") { |
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.
| std::string fmt_arg = args[1]; | |
| std::transform(fmt_arg.begin(), fmt_arg.end(), fmt_arg.begin(), ::tolower); | |
| if (fmt_arg == "iso8601") { | |
| if (util::EqualICase(args[1], "iso8601")) { |
src/commands/cmd_server.cc
Outdated
| *output = redis::Integer(unix_sec); | ||
| if (format_spec_) { | ||
| time_t raw_time = static_cast<time_t>(unix_sec); | ||
| struct tm *local_time = localtime(&raw_time); |
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.
We can use the thread-safe version localtime_r.
src/commands/cmd_server.cc
Outdated
| strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", local_time); | ||
| *output = redis::BulkString(buf); | ||
| } else { | ||
| *output = redis::BulkString("Error converting time"); |
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.
| *output = redis::BulkString("Error converting time"); | |
| *output = redis::BulkString("Failed to convert timestamp to local time"); |
PragmaTwice
left a comment
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.
Looks good. Could you add a go test case for your changes?
I am a bit confused about where exactly to add the test for |
|
You can add a new go source file under |
Update src/commands/cmd_server.cc Co-authored-by: hulk <[email protected]> Update src/commands/cmd_server.cc Update src/commands/cmd_server.cc Update src/commands/cmd_server.cc Co-authored-by: Twice <[email protected]> Update src/commands/cmd_server.cc Co-authored-by: Twice <[email protected]>
c9fa4f2 to
f48e86e
Compare
|
Looks good. @SharonIV0x86 You could use the gofmt to format Go files to pass the CI. |
|


This closes #2817.
This PR introduces a new parameter to the
LASTSAVEcommand to return the time of last save to disk in a human readable format.Usage
LASTSAVE ISO8601LASTSAVE iso8601LASTSAVEalso works for backward compatibility.