Skip to content

fix(geo): support case insensitive units #4264

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

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/server/zset_family.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1732,13 +1732,14 @@ void ZAddGeneric(string_view key, const ZParams& zparams, ScoredMemberSpan memb_
}

double ExtractUnit(std::string_view arg) {
if (arg == "M") {
const string unit = absl::AsciiStrToUpper(arg);
if (unit == "M") {
return 1;
} else if (arg == "KM") {
} else if (unit == "KM") {
return 1000;
} else if (arg == "FT") {
} else if (unit == "FT") {
return 0.3048;
} else if (arg == "MI") {
} else if (unit == "MI") {
return 1609.34;
} else {
return -1;
Expand Down Expand Up @@ -2719,8 +2720,7 @@ void ZSetFamily::GeoDist(CmdArgList args, const CommandContext& cmd_cntx) {
auto* rb = static_cast<RedisReplyBuilder*>(cmd_cntx.rb);

if (args.size() == 4) {
string unit = absl::AsciiStrToUpper(ArgS(args, 3));

string_view unit = ArgS(args, 3);
distance_multiplier = ExtractUnit(unit);
args.remove_suffix(1);
if (distance_multiplier < 0) {
Expand Down
Loading