@@ -773,7 +773,7 @@ void GeoFamily::GeoRadiusByMember(CmdArgList args, const CommandContext& cmd_cnt
773
773
GeoSearchStoreGeneric (cmd_cntx.tx , builder, shape, key, member, geo_ops);
774
774
}
775
775
776
- void GeoFamily::GeoRadius (CmdArgList args, const CommandContext& cmd_cntx) {
776
+ void GeoFamily::GeoRadiusGeneric (CmdArgList args, const CommandContext& cmd_cntx, bool read_only ) {
777
777
GeoShape shape = {};
778
778
GeoSearchOpts geo_ops;
779
779
@@ -789,12 +789,21 @@ void GeoFamily::GeoRadius(CmdArgList args, const CommandContext& cmd_cntx) {
789
789
shape.type = CIRCULAR_TYPE;
790
790
791
791
while (parser.HasNext ()) {
792
+ // try and parse for only RO options first
792
793
auto type =
793
- parser.MapNext (" STORE" , Type::STORE, " STOREDIST" , Type::STOREDIST, " ASC" , Type::ASC, " DESC" ,
794
- Type::DESC, " COUNT" , Type::COUNT, " WITHCOORD" , Type::WITHCOORD, " WITHDIST" ,
795
- Type::WITHDIST, " WITHHASH" , Type::WITHHASH);
794
+ parser.TryMapNext (" ASC" , Type::ASC, " DESC" , Type::DESC, " COUNT" , Type::COUNT, " WITHCOORD" ,
795
+ Type::WITHCOORD, " WITHDIST" , Type::WITHDIST, " WITHHASH" , Type::WITHHASH);
796
+ // if writing variant and there there was a mapping failure test for write variant arguments
797
+ if (!type && !read_only) {
798
+ type = parser.MapNext (" STORE" , Type::STORE, " STOREDIST" , Type::STOREDIST);
799
+ }
796
800
797
- switch (type) {
801
+ // could not map the argument to an argument for RO or write GEORADIUS
802
+ if (!type) {
803
+ return builder->SendError (" syntax error" , kSyntaxErrType );
804
+ }
805
+
806
+ switch (*type) {
798
807
case Type::STORE:
799
808
geo_ops.store_key = parser.Next ();
800
809
geo_ops.store = geo_ops.store == GeoStoreType::kNoStore ? GeoStoreType::kStoreHash
@@ -867,6 +876,14 @@ void GeoFamily::GeoRadius(CmdArgList args, const CommandContext& cmd_cntx) {
867
876
GeoSearchStoreGeneric (cmd_cntx.tx , builder, shape, key, " " , geo_ops);
868
877
}
869
878
879
+ void GeoFamily::GeoRadius (CmdArgList args, const CommandContext& cmd_cntx) {
880
+ GeoRadiusGeneric (args, cmd_cntx, false );
881
+ }
882
+
883
+ void GeoFamily::GeoRadiusRO (CmdArgList args, const CommandContext& cmd_cntx) {
884
+ GeoRadiusGeneric (args, cmd_cntx, true );
885
+ }
886
+
870
887
#define HFUNC (x ) SetHandler(&GeoFamily::x)
871
888
872
889
namespace acl {
@@ -877,21 +894,21 @@ constexpr uint32_t kGeoDist = READ | GEO | SLOW;
877
894
constexpr uint32_t kGeoSearch = READ | GEO | SLOW;
878
895
constexpr uint32_t kGeoRadiusByMember = WRITE | GEO | SLOW;
879
896
constexpr uint32_t kGeoRadius = WRITE | GEO | SLOW;
897
+ constexpr uint32_t kGeoRadiusRO = READ | GEO | SLOW;
880
898
} // namespace acl
881
899
882
900
void GeoFamily::Register (CommandRegistry* registry) {
883
901
registry->StartFamily ();
884
- *registry << CI{" GEOADD" , CO::FAST | CO::WRITE | CO::DENYOOM, -5 , 1 , 1 , acl::kGeoAdd }.HFUNC (
885
- GeoAdd)
886
- << CI{" GEOHASH" , CO::FAST | CO::READONLY, -2 , 1 , 1 , acl::kGeoHash }.HFUNC (GeoHash)
887
- << CI{" GEOPOS" , CO::FAST | CO::READONLY, -2 , 1 , 1 , acl::kGeoPos }.HFUNC (GeoPos)
888
- << CI{" GEODIST" , CO::READONLY, -4 , 1 , 1 , acl::kGeoDist }.HFUNC (GeoDist)
889
- << CI{" GEOSEARCH" , CO::READONLY, -7 , 1 , 1 , acl::kGeoSearch }.HFUNC (GeoSearch)
890
- << CI{" GEORADIUSBYMEMBER" , CO::WRITE | CO::STORE_LAST_KEY, -5 , 1 , 1 ,
891
- acl::kGeoRadiusByMember }
892
- .HFUNC (GeoRadiusByMember)
893
- << CI{" GEORADIUS" , CO::WRITE | CO::STORE_LAST_KEY, -6 , 1 , 1 , acl::kGeoRadius }.HFUNC (
894
- GeoRadius);
902
+ *registry
903
+ << CI{" GEOADD" , CO::FAST | CO::WRITE | CO::DENYOOM, -5 , 1 , 1 , acl::kGeoAdd }.HFUNC (GeoAdd)
904
+ << CI{" GEOHASH" , CO::FAST | CO::READONLY, -2 , 1 , 1 , acl::kGeoHash }.HFUNC (GeoHash)
905
+ << CI{" GEOPOS" , CO::FAST | CO::READONLY, -2 , 1 , 1 , acl::kGeoPos }.HFUNC (GeoPos)
906
+ << CI{" GEODIST" , CO::READONLY, -4 , 1 , 1 , acl::kGeoDist }.HFUNC (GeoDist)
907
+ << CI{" GEOSEARCH" , CO::READONLY, -7 , 1 , 1 , acl::kGeoSearch }.HFUNC (GeoSearch)
908
+ << CI{" GEORADIUSBYMEMBER" , CO::WRITE | CO::STORE_LAST_KEY, -5 , 1 , 1 , acl::kGeoRadiusByMember }
909
+ .HFUNC (GeoRadiusByMember)
910
+ << CI{" GEORADIUS" , CO::WRITE | CO::STORE_LAST_KEY, -6 , 1 , 1 , acl::kGeoRadius }.HFUNC (GeoRadius)
911
+ << CI{" GEORADIUS_RO" , CO::READONLY, -6 , 1 , 1 , acl::kGeoRadiusRO }.HFUNC (GeoRadiusRO);
895
912
}
896
913
897
914
} // namespace dfly
0 commit comments