geoRadius - How to?
Description
I am running a 6.0.14 redis server (in Azure) and want to use the geoRadius search that includes the coordinates (WITHCOORD). It is really hard to find in the documentation how exactly the call would look like.
Any idea anyone?
client.GEORADIUS_WITHCOORDS/client.geoRadiusWithCoords should do the trick
Not sure, what that means. There is no geoRadiusWithCoords, at least to what I see....
I suspect, those additional attributes are not implemented in the latest version.
I checked the file @redis/client/dist/lib/commands/generic-transformers.js and updated the function pushGeoRadsArgumentsas follows
function pushGeoRadiusArguments(args, key, from, radius, unit, options) {
var geoRadiusAdditionInfo = ["WITHDIST", "WITHCOORD", "WITHHASH"];
args.push(key);
if (typeof from === 'string') {
args.push(from);
}
else {
args.push(from.longitude.toString(), from.latitude.toString());
}
args.push(radius.toString(), unit);
geoRadiusAdditionInfo.forEach(info => {
if (options && options[info] && options[info] == true){
args.push(info);
}
});
if (options?.SORT) {
args.push(options.SORT);
}
pushGeoCountArgument(args, options?.COUNT);
return args;
}
So now, one could call client.geoRadius ('key', {longitude: location[0], latitude: location[1]}, radius, 'km',{WITHCOORD: true});
Could that be included in the lib?
@asindl my bad, it's not client.GEORADIUS_WITHCOORDS it's client.GEORADIUS_WITH:
import { GeoReplyWith } from 'redis';
await client.GEORADIUS_WITH(
'key',
{ longitude: location[0], latitude: location[1] },
radius,
'km',
[GeoReplyWith.WITH_COORDS]
);
in general, when a command argument changes the reply type, its implemented as its own command (to allow for better types).
Thanks a lot, @leibale!
Small correction: the attribute name is COORDINATES': GeoReplyWith["COORDINATES"] = "WITHCOORD";`
So, you example needs to be
import { GeoReplyWith } from 'redis';
await client.GEORADIUS_WITH(
'key',
{ longitude: location[0], latitude: location[1] },
radius,
'km',
[GeoReplyWith.COORDINATES]
);
Now, it works like a charm!
Since I suspected, it would work "somehow", I labeled this as "documentation". Is there any documentation about the usage of this including the response types? If not, it would be helpful to add it...
Thanks again!