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

Implement more of GEOSEARCH functionality. #1058

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
522 changes: 522 additions & 0 deletions libs/resources/RespCommandsDocs.json

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions libs/resources/RespCommandsInfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,162 @@
}
]
},
{
"Command": "GEORADIUS",
"Name": "GEORADIUS",
"Arity": -6,
"Flags": "DenyOom, MovableKeys, Write",
"FirstKey": 1,
"LastKey": 1,
"Step": 1,
"AclCategories": "Geo, Slow, Write",
"KeySpecifications": [
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchIndex",
"Index": 1
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "RO, Access"
},
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchKeyword",
"Keyword": "STORE",
"StartFrom": 6
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "OW, Update"
},
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchKeyword",
"Keyword": "STOREDIST",
"StartFrom": 6
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "OW, Update"
}
]
},
{
"Command": "GEORADIUS_RO",
"Name": "GEORADIUS_RO",
"Arity": -6,
"Flags": "ReadOnly",
"FirstKey": 1,
"LastKey": 1,
"Step": 1,
"AclCategories": "Geo, Read, Slow",
"KeySpecifications": [
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchIndex",
"Index": 1
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "RO, Access"
}
]
},
{
"Command": "GEORADIUSBYMEMBER",
"Name": "GEORADIUSBYMEMBER",
"Arity": -5,
"Flags": "DenyOom, MovableKeys, Write",
"FirstKey": 1,
"LastKey": 1,
"Step": 1,
"AclCategories": "Geo, Slow, Write",
"KeySpecifications": [
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchIndex",
"Index": 1
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "RO, Access"
},
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchKeyword",
"Keyword": "STORE",
"StartFrom": 5
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "OW, Update"
},
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchKeyword",
"Keyword": "STOREDIST",
"StartFrom": 5
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "OW, Update"
}
]
},
{
"Command": "GEORADIUSBYMEMBER_RO",
"Name": "GEORADIUSBYMEMBER_RO",
"Arity": -5,
"Flags": "ReadOnly",
"FirstKey": 1,
"LastKey": 1,
"Step": 1,
"AclCategories": "Geo, Read, Slow",
"KeySpecifications": [
{
"BeginSearch": {
"TypeDiscriminator": "BeginSearchIndex",
"Index": 1
},
"FindKeys": {
"TypeDiscriminator": "FindKeysRange",
"LastKey": 0,
"KeyStep": 1,
"Limit": 0
},
"Flags": "RO, Access"
}
]
},
{
"Command": "GEOSEARCH",
"Name": "GEOSEARCH",
Expand Down
26 changes: 24 additions & 2 deletions libs/server/Objects/SortedSet/SortedSetObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public enum SortedSetOperation : byte
GEODIST,
GEOPOS,
GEOSEARCH,
GEOSEARCHSTORE,
ZREVRANK,
ZREMRANGEBYLEX,
ZREMRANGEBYRANK,
Expand Down Expand Up @@ -77,6 +76,30 @@ public enum SortedSetRangeOpts : byte
WithScores = 1 << 4
}

/// <summary>
/// Options for specifying command type in sorted set geo operations.
/// </summary>
[Flags]
public enum SortedSetGeoOpts : byte
{
/// <summary>
/// No options specified.
/// </summary>
None = 0,
/// <summary>
/// ReadOnly operation.
/// </summary>
ReadOnly = 1,
/// <summary>
/// Operate by radius.
/// </summary>
ByRadius = 1 << 1,
/// <summary>
/// Get lonlat from member.
/// </summary>
ByMember = 1 << 2
}

[Flags]
public enum SortedSetAddOption
{
Expand Down Expand Up @@ -298,7 +321,6 @@ public override unsafe bool Operate(ref ObjectInput input, ref GarnetObjectStore
GeoPosition(ref input, ref output.SpanByteAndMemory);
break;
case SortedSetOperation.GEOSEARCH:
case SortedSetOperation.GEOSEARCHSTORE:
GeoSearch(ref input, ref output.SpanByteAndMemory);
break;
case SortedSetOperation.ZRANGE:
Expand Down
14 changes: 14 additions & 0 deletions libs/server/Objects/SortedSetGeo/GeoHash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ public static double Distance(double sourceLat, double sourceLon, double targetL
return 2 * Math.Asin(Math.Sqrt(latHaversine + (tmp * lonHaversine))) * EarthRadiusInMeters;
}

/// <summary>
/// Find if a point is in the circle.
/// </summary>
public static bool GetDistanceWhenInCircle(double radius, double latCenterPoint, double lonCenterPoint, double lat2, double lon2, ref double distance)
{
distance = Distance(latCenterPoint, lonCenterPoint, lat2, lon2);
if (distance > radius)
{
return false;
}

return true;
}

/// <summary>
/// Find if a point is in the axis-aligned rectangle.
/// when the distance between the searched point and the center point is less than or equal to
Expand Down
Loading