Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

#1250: Add support for GEORADIUS #1321

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 8 additions & 0 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@
is not parsable as floating point number, then an error occurs.
`,
Arity: -4,
KeySpecs: KeySpecs{BeginIndex: 1},

Check failure on line 1304 in internal/eval/commands.go

View workflow job for this annotation

GitHub Actions / lint

var `geoRadiusCmdMeta` is unused (unused)
IsMigrated: true,
NewEval: evalHINCRBYFLOAT,
}
Expand All @@ -1321,6 +1321,14 @@
NewEval: evalGEODIST,
KeySpecs: KeySpecs{BeginIndex: 1},
}
geoRadiusCmdMeta = DiceCmdMeta{
Name: "GEORADIUS",
Info: `Returns members of a sorted set with geospatial data that lie within a specified radius from a given center location.`,
Arity: -5,
IsMigrated: true,
NewEval: evalGEORADIUS,
KeySpecs: KeySpecs{BeginIndex: 1},
}
jsonstrappendCmdMeta = DiceCmdMeta{
Name: "JSON.STRAPPEND",
Info: `JSON.STRAPPEND key [path] value
Expand Down
118 changes: 118 additions & 0 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -6333,6 +6333,124 @@
}
}

func evalGEORADIUS(args []string, store *dstore.Store) *EvalResponse {

Check failure on line 6336 in internal/eval/store_eval.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 31 of func `evalGEORADIUS` is high (> 30) (gocyclo)

Check failure on line 6336 in internal/eval/store_eval.go

View workflow job for this annotation

GitHub Actions / lint

func `evalGEORADIUS` is unused (unused)
if len(args) < 3 || len(args) > 4 {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrWrongArgumentCount("GEORADIUS"),
}
}

key := args[0]

longitude, err := strconv.ParseFloat(args[1], 64)
if err != nil {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("value is not a valid float"),
}
}

latitude, err := strconv.ParseFloat(args[2], 64)
if err != nil {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("value is not a valid float"),
}
}

if math.IsNaN(latitude) || math.IsNaN(longitude) || longitude < -180 || longitude > 180 || latitude < -85.05112878 || latitude > 85.05112878 {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrFormatted("invalid longitude,latitude pair %v %v", longitude, latitude),
}
}
unit := strings.ToUpper(args[4])
if unit != "M" && unit != "KM" && unit != "MI" && unit != "FT" {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("unsupported unit provided. please use M, KM, FT, MI"),
}
}

var withCoord, withDist, withHash, countAny bool
var sortOrder, storeKey, storeDistKey string
var countValue int

//Parse optional parameters
for i := 5; i < len(args); i++ {
option := strings.ToUpper(args[i])

switch {
case option == "WITHCOORD":
withCoord = true
case option == "WITHDIST":
withDist = true
case option == "WITHHASH":
withHash = true
case option == "ASC" || option == "DESC":
sortOrder = option
case option == "COUNT":
if i+1 < len(args) {
count, err := strconv.Atoi(args[i+1])
if err != nil {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrIntegerOutOfRange,
}
}
countValue = count
if i+2 < len(args) && strings.ToUpper(args[i+2]) == "ANY" {

Check failure on line 6403 in internal/eval/store_eval.go

View workflow job for this annotation

GitHub Actions / lint

string `ANY` has 2 occurrences, make it a constant (goconst)
countAny = true
i++
}
i++
} else {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("syntax error"),
}
}
case option == "ANY":
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("the ANY argument requires COUNT argument"),
}
case option == "STORE":
if i+1 < len(args) {
storeKey = args[i+1]
i++
} else {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("syntax error"),
}
}
case option == "STOREDIST":
if i+1 < len(args) {
storeDistKey = args[i+1]
i++
} else {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("syntax error"),
}
}
default:
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrGeneral("syntax error"),
}
}
}

fmt.Println(key, longitude, latitude, unit, withCoord, withDist, withHash, sortOrder, countAny, countValue, storeKey, storeDistKey)
return &EvalResponse{
Result: nil,
Error: nil,
}
}

func evalTouch(args []string, store *dstore.Store) *EvalResponse {
if len(args) != 1 {
return makeEvalError(diceerrors.ErrWrongArgumentCount("TOUCH"))
Expand Down
Loading