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

GEORADIUSBYMEMBER command #1294

Open
wants to merge 11 commits into
base: master
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
github.com/google/uuid v1.6.0
github.com/gorilla/websocket v1.5.3
github.com/mattn/go-sqlite3 v1.14.24
github.com/mmcloughlin/geohash v0.10.0
github.com/ohler55/ojg v1.25.0
github.com/rs/xid v1.6.0
github.com/rs/zerolog v1.33.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mmcloughlin/geohash v0.10.0 h1:9w1HchfDfdeLc+jFEf/04D27KP7E2QmpDu52wPbJWRE=
github.com/mmcloughlin/geohash v0.10.0/go.mod h1:oNZxQo5yWJh0eMQEP/8hwQuVx9Z9tjwFUqcTB1SmG0c=
github.com/ohler55/ojg v1.25.0 h1:sDwc4u4zex65Uz5Nm7O1QwDKTT+YRcpeZQTy1pffRkw=
github.com/ohler55/ojg v1.25.0/go.mod h1:gQhDVpQLqrmnd2eqGAvJtn+NfKoYJbe/A4Sj3/Vro4o=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
Expand Down
19 changes: 19 additions & 0 deletions internal/clientio/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ func Encode(value interface{}, isSimple bool) []byte {
buf.Write(encodeString(b)) // Encode each string and write to the buffer.
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes())) // Return the encoded response.
case [][]interface{}:
var b []byte
buf := bytes.NewBuffer(b)

buf.WriteString(fmt.Sprintf("*%d\r\n", len(v)))

for _, list := range v {
buf.Write(Encode(list, false))
}
return buf.Bytes()

// Handle slices of custom objects (Obj).
case []*object.Obj:
Expand All @@ -255,6 +265,15 @@ func Encode(value interface{}, isSimple bool) []byte {
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes())) // Return the encoded response.

// Handle slices of int64.
case []float64:
var b []byte
buf := bytes.NewBuffer(b) // Create a buffer for accumulating encoded values.
for _, b := range value.([]float64) {
buf.Write(Encode(b, false)) // Encode each int64 and write to the buffer.
}
return []byte(fmt.Sprintf("*%d\r\n%s", len(v), buf.Bytes())) // Return the encoded response.

// Handle slices of int64.
case []int64:
var b []byte
Expand Down
2 changes: 2 additions & 0 deletions internal/errors/migrated_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
ErrInvalidFingerprint = errors.New("invalid fingerprint")
ErrKeyDoesNotExist = errors.New("ERR could not perform this operation on a key that doesn't exist")
ErrKeyExists = errors.New("ERR key exists")
ErrInvalidFloat = errors.New("ERR value is not a valid float")
ErrUnsupportedUnit = errors.New("ERR unsupported unit provided. please use m, km, ft, mi")

// Error generation functions for specific error messages with dynamic parameters.
ErrWrongArgumentCount = func(command string) error {
Expand Down
9 changes: 9 additions & 0 deletions internal/eval/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,6 +1301,14 @@ var (
NewEval: evalGEODIST,
KeySpecs: KeySpecs{BeginIndex: 1},
}
geoRadiusByMemberCmdMeta = DiceCmdMeta{
Name: "GEORADIUSBYMEMBER",
Info: `Returns all members within a radius of a given member from the geospatial index.`,
Arity: -4,
IsMigrated: true,
NewEval: evalGEORADIUSBYMEMBER,
KeySpecs: KeySpecs{BeginIndex: 1},
}
jsonstrappendCmdMeta = DiceCmdMeta{
Name: "JSON.STRAPPEND",
Info: `JSON.STRAPPEND key [path] value
Expand Down Expand Up @@ -1444,6 +1452,7 @@ func init() {
DiceCmds["FLUSHDB"] = flushdbCmdMeta
DiceCmds["GEOADD"] = geoAddCmdMeta
DiceCmds["GEODIST"] = geoDistCmdMeta
DiceCmds["GEORADIUSBYMEMBER"] = geoRadiusByMemberCmdMeta
DiceCmds["GET"] = getCmdMeta
DiceCmds["GETBIT"] = getBitCmdMeta
DiceCmds["GETDEL"] = getDelCmdMeta
Expand Down
Loading