fix(geo): support case insensitive units (#4264)

This commit is contained in:
Andy Dunstall 2024-12-05 15:01:23 +00:00 committed by GitHub
parent 17651b2610
commit 63ccbbc0a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1732,13 +1732,14 @@ void ZAddGeneric(string_view key, const ZParams& zparams, ScoredMemberSpan memb_
} }
double ExtractUnit(std::string_view arg) { double ExtractUnit(std::string_view arg) {
if (arg == "M") { const string unit = absl::AsciiStrToUpper(arg);
if (unit == "M") {
return 1; return 1;
} else if (arg == "KM") { } else if (unit == "KM") {
return 1000; return 1000;
} else if (arg == "FT") { } else if (unit == "FT") {
return 0.3048; return 0.3048;
} else if (arg == "MI") { } else if (unit == "MI") {
return 1609.34; return 1609.34;
} else { } else {
return -1; return -1;
@ -2719,8 +2720,7 @@ void ZSetFamily::GeoDist(CmdArgList args, const CommandContext& cmd_cntx) {
auto* rb = static_cast<RedisReplyBuilder*>(cmd_cntx.rb); auto* rb = static_cast<RedisReplyBuilder*>(cmd_cntx.rb);
if (args.size() == 4) { if (args.size() == 4) {
string unit = absl::AsciiStrToUpper(ArgS(args, 3)); string_view unit = ArgS(args, 3);
distance_multiplier = ExtractUnit(unit); distance_multiplier = ExtractUnit(unit);
args.remove_suffix(1); args.remove_suffix(1);
if (distance_multiplier < 0) { if (distance_multiplier < 0) {