arjunmehta / node-georedis Goto Github PK
View Code? Open in Web Editor NEWSuper fast geo queries.
License: MIT License
Super fast geo queries.
License: MIT License
Is there a way to set expiry to a member in a key.
Hello and thanks for the great repo. Can you briefly explain the reason for using MULTI/EXEC? I am scaling redis using Twemproxy and unfortunately transaction operations are not supported. With that being said is there a way to implement emulation on a distributed redis cluster? Take note that twemproxy can route requests to appropriate shard via hash_tag. Twemproxy can also route requests by port to a sole redis instance provided in nutcracker configuration.
Hey, thanks for this awesome library.
I was wondering about the difference between addLocation
and updateLocation
- in my application, I am looking to do an "upsert" - just to add or update depending on if the location already exists. Does one or both of these methods already expose this functionality? And if not, is there a way to avoid doing a get
and then an update
or add
depending on the existence of the value returned by get?
Hi,
It's a really interesting and great library, thanks for saving lot of our work.
I am getting below error when I run nearby
in redis cluster.
{"correlationId":"89a9922e-019d-47d5-a8fd-804ae261b3b0","data":{"message":"MOVED 3400 10.20.41.108:6379","statusCode":500}}
What could be the reason, does it support cluster? I am using Amazon ElastiCache
Also while removing data using removeLocations
getting below error
{"correlationId":"472b05c8-c73f-4e88-96ef-69072be8e510","data":{"message":"ERR wrong number of arguments for 'zrem' command","statusCode":500}}
I keep getting the redis errors on my server as a result on the initialization of this library. Here is the problem area of the code:
client.send_command('command', nativeCommands, function(err, response) {
if (!err) {
if (Array.isArray(response) && Array.isArray(response[0]) && response[0][0] === 'geoadd') {
set.clientInterface = new NativeInterface(client);
}
}
});
Is there another command to send instead of command? to determine whether of not to use native or emulated, perhaps maybe INFO instead of COMMAND? I am trying to troubleshoot an issue with twemproxy and its hard to do so with all of the errors "unsupported command 'COMMAND'" in the error logs
Hi,
Is there a difference between the performance of addLocation and update? I've been using addLocation as an update procedure as well.
Lets say we have the following coordinate which we want to add
longitude,latitude
121.16625075805472,14.55976969490166
Now, if we try to insert it using node-georedis, it was inserted successfully, but the inserted coordinates are different from original. Why is that?
longitude,latitude
121.16625219583511353,14.55976912035422544
Thanks for providing nice package,
`// will find all PEOPLE ~5000m from the passed in coordinate
people.nearby({latitude: 43.646838, longitude: -79.403723}, 5000, function(err, people){
if(err) console.error(err)
else console.log('people nearby:', people)
})
// will find all PLACES ~5000m from the passed in coordinate
places.nearby({latitude: 43.646838, longitude: -79.403723}, 5000, function(err, places){
if(err) console.error(err)
else console.log('places nearby:', places)
})`
Is it possible to merge result from two sets (people and places) and then send as a single result? something like this -
`// will find all PEOPLE ~5000m from the passed in coordinate
people.nearby({latitude: 43.646838, longitude: -79.403723}, 5000, function(err, people){
if(err) console.error(err)
else result['b'] = people
})
// will find all PLACES ~5000m from the passed in coordinate
places.nearby({latitude: 43.646838, longitude: -79.403723}, 5000, function(err, places){
if(err) console.error(err)
else result['a'] = places
})And then
return res.send(result)`
Please help me, I've asked this question at stack overflow but didn't get any answer
http://stackoverflow.com/questions/38238402/how-to-send-multiple-objects-using-nodejs-and-georedis
This is a continuation of arjunmehta/node-geo-proximity#19
First off thanks for the re-write and the sorting!
I'm using nearby()
with fakeredis and getting the following error:
Error: fakeredis: COMMAND is not implemented in fakeredis. Let me know if you need it.
From what I can tell, it looks like it is using georadius
. Any idea if this error is coming from your code or fake redis? My hunch is the latter - and if so you know any workaround?
As I mentioned in the previous issue, I have to use fakeredis because I am using AWS lambda which does not currently have access to a redis server (via elasticache). Also my data set is pretty small so would like to pay the potential performance penalty to remove another thing I have to keep Highly Available.
Any ideas?
Here is my code (roughly):
...
var defaultNumResults = 10,
defaultRadius = 10,
redisClient = null,
placeProximity = null,
nearbyOptions = {
withCoordinates: false, // Will provide coordinates with locations, default false
withHashes: false, // Will provide a 52bit Geohash Integer, default false
withDistances: true, // Will provide distance from query, default false
order: 'ASC', // or 'DESC' or true (same as 'ASC'), default false
units: 'mi', // or 'km', 'mi', 'ft', default 'm'
count: 10, // Number of results to return, default undefined
accurate: true, // Useful if in emulated mode and accuracy is important, default false
};
exports.closestPlaces = function(lat, lng, numResults, radius) {
if (!placeProximity) {
redisClient = require('fakeredis').createClient(0, '', {
fast: true,
});
placeProximity = Promise.promisifyAll(require('georedis')).initialize(redisClient);
}
//Fastest: http://stackoverflow.com/questions/5349425/whats-the-fastest-way-to-loop-through-an-array-in-javascript
for (var i = 0, len = channelsList.length; i < len; i++) {
var entry = channelsList[i];
try {
placeProximity.addLocation(JSON.stringify(entry), {
latitude: entry.lat,
longitude: entry.lng,
}, function(err, reply) {
if (err) {
console.error('error adding', entry, err);
return Promise.reject(new MlnError(
'Error adding' + JSON.stringify(entry, null, 2),
MlnError.errorCodes.UNKNOWN
));
}
});
} catch (e) {
console.error('Error adding location', entry, e);
return Promise.resolve([]);
}
}
nearbyOptions.count = numResults || defaultNumResults;
return placeProximity.nearbyAsync({latitude: lat, longitude: lng}, radius || defaultRadius, options)
.then(function(locations) {
return locations;
})
.catch(function(e) {
return []; //any error return cant find
});
};
From Location() api => null { latitude: 43.64728555083275, longitude: -79.40306156873703 }
nearby locations: { '4': { key: [ '4' ], latitude: null, longitude: null },
null: { key: null, latitude: null, longitude: null },
'': { key: [], latitude: null, longitude: null } }
Got Data from Paged Results []
nearby locations: [ { latitude: -89.99999865889549,
longitude: -179.99999731779099,
key: 'null' } ]
Hi,
I am trying to store the lat long as:
{"lat":29.419506,"long":79.038539}
But on querying the position, it returns:
27.80180134535769554 79.03853863477706909
Same is the case with any other position. Also the variation is not fixed.
let result = await store.nearby({ latitude: lat, longitude: lng }, 30);
Hi,
I am using redis server 3.2.3 which supports native geo command.
I found that if I call nearby()
function with the following options, the results will be very limited (I guess the unit used isn't correct)
{
withCoordinates: true,
withDistances: true,
units: 'mi',
accurate: true
}
My peer uses old redis server (3.0.7), it works fine with the same code. Then I tried to append nativeGeo: true
on initialization, everything goes well. But my server doesn't support native geo command, it will be great and better let the lib determine whether to use native command.
Thanks :]
https://gis.stackexchange.com/questions/18330/using-geohash-for-proximity-searches/228494#228494 I am trying to implement the algorithm in Python that you have published on the GIS SE site.
Here is where I am currently.
I have the following box which is like this
minLat, maxLat : 0.05
minLon,maxLon : 0.05
So my coordinate set is a grid with a grid spacing of 0.05 degrees. The boundaries of the grid are marked by minLat,maxLat,minLon,maxLon. In my case the data grid is a constant and will never change.
So for each grid coordinate(gridLat,gridLon) I encode using a geohash and calculate it's eight neighbors as well. For me the precision is 26 because my query window is 5 kms(query window will never change)
Then I add one to the 9 members above. So I have 18 members in total.
Since my data set is evenly distributed can I store these in a HashMap because the lookup can be of complexity O(1) ?
I'm bulk importing millions of geos and other keys and would like to do this via a single file generated using the redis protocol (http://redis.io/topics/mass-insert). Is there a way to generate the georedis insert/set commands?
Good day,
I would like to implement geohashing based on your module, but using own storage ( not redis ).
Currently I store locations as int geohash (bit depth 52). For one location this is: 3672837726667608
By using the module I can calculate ranges based on location and radius. The result is:
[ 3672437556248576, 3672506275725312 ],
[ 3672574995202048, 3672918592585728 ],
[ 3672987312062464, 3673056031539200 ],
[ 3673193470492672, 3673330909446144 ]
My question:
Thank you.
I need to save additional data ("authorID" and "workshopID") to the locations saved. Right now there's only a field for the 'locationName'. The only way I can save the extra data is if I save a JSON as a string into the locationName field. This means I have to parse each locationName as a JSON when I retrieve the location. Is there any other way to do this?
var locationSet = {
'Toronto': {latitude: 43.6667, longitude: -79.4167,label:"a"},
'Philadelphia': {latitude: 39.9523, longitude: -75.1638,label:"b"},
'Palo Alto': {latitude: 37.4688, longitude: -122.1411,label:"c"},
'San Francisco': {latitude: 37.7691, longitude: -122.4449,label:"b"},
'St. John's': {latitude: 47.5500, longitude: -52.6667,label:"a"},
'New York': {latitude: 40.7143, longitude: -74.0060,label:"b"},
'Twillingate': {latitude: 49.6500, longitude: -54.7500,label:"a"},
'Ottawa': {latitude: 45.4167, longitude: -75.7000,label:"b"},
'Calgary': {latitude: 51.0833, longitude: -114.0833,label:"a"},
'Mumbai': {latitude: 18.9750, longitude: 72.8258,label:"c"}
}
geo.nearby('Toronto',50000000, options,function(err, locations){
if(err) console.error(err)
else console.log('nearby locations:', locations);
});
i want to get nearby with respect label,
Hey! I noticed that when doing a query like:
geo.nearby(location, 0.5, { withDistances: true, units: 'mi' }, function(err, locations) {
// locations contain a distance key, but the distance is in meters
})
Not a big deal (I can do the conversion on my side), but I figured it might be nice to have the units be consistent if it's an easy change.
My app shows a list of nearby ATMs.
At first only the 20 closest ATMs are shown in the list (see screenshot below). When the user scrolls, more ATMs are loaded from node-georedis. As the user scrolls more and more, they get further and further ATMs.
An ideal geographic database would return ATMs in concentric rings, allowing an offset
parameter in the request, and keeping a kind of cache internally so that subsequent requests do not cost more and more CPU/memory.
If would be great if node-georedis could provide this paging. Meanwhile, if you have any tricks for dealing with this kind of situation I would be glad to hear about them :-) Cheers!
Hi,
GeoRedis feature currently utilizes 3 properties: latitude, longitude, and name. When adding a location, is it possible to add additional key value pairs aside from name itself? Let us say we are adding name, address, etc. Is it possible? If not, what are best workaround / practices?
Im using below options and get nearby orders :
var options = {
withCoordinates: true, // Will provide coordinates with locations, default false
withHashes: true, // Will provide a 52bit Geohash Integer, default false
withDistances: true, // Will provide distance from query, default false
order: 'ASC', // or 'DESC' or true (same as 'ASC'), default false
units: 'km', // or 'km', 'mi', 'ft', default 'm'
count: 100, // Number of results to return, default undefined
accurate: true // Useful if in emulated mode and accuracy is important, default false
}
// look for all points within ~5000m of Toronto with the options.
geo.nearby({latitude: 43.646838, longitude: -79.403723}, 3, options, function(err, locations){
if(err) console.error(err)
else console.log('nearby locations:', locations)
})
Local Mechine :
In my local mechine my using below version
Node Redis client: 2.71
Redis-Server : 2.4.6
Already set the orders with locations and using nearby location i can get the orders within 3kms.
AWS Server :
Node Redis client: 2.71
Redis-Server : 3.4
when emit 3km i can't get the orders and i can get orders within 0.68 Km only.
I can't get the solutions. Let me know if anything version problem.
node_redis: Deprecated: The ZADD command contains a "undefined" argument.
This is converted to a "undefined" string now and will return an error from v.3.0 on.
Please handle this in your code to make sure everything works as you intended it to.
var geo = georedis.initialize(client, {
zset: 'acceptToStart',
nativeGeo: false
});
If you can check and fix. why I am getting this error. How can I fix this.
Currently it is not possible to use readonly variants GEORADIUS_RO and GEORADIUSBYMEMBER_RO. Please add these readonly variants.
See:
I am trying to use 'ioredis' with georedis but getting error
` const Redis = require("ioredis");
const redisClient = new Redis(
config.get('database').redis.port,
config.get('database').redis.ip);
let geo = require('georedis').initialize(redisClient);
let driverslocations = geo.addSet('abc');`
getting this ERROR
ReplyError: ERR syntax error. Try GEOADD key [x1] [y1] [name1] [x2] [y2] [name2
"ioredis": "^4.17.3",
"georedis": "3.1.1",
Hi,
Would it be possible to publish a new release to NPM registry? The current release (3.0.3) is already one year old and is missing for example the following commit: bbf88ba. Without the fix introduced in the commit the module crashes if the "geo.location" function is called for an id that is not present or has already been deleted.
Thanks! :)
I retrieve locations with the nearby
method. However I see the following errors:
{ AbortError: GEORADIUS can't be processed. The connection is already closed.}
at handle_offline_command (/srv/node_modules/redis/index.js:851:15)
at RedisClient.internal_send_command (/srv/node_modules/redis/index.js:885:9)
at RedisClient.georadius (/srv/node_modules/redis/lib/commands.js:58:25)
at RedisClient.send_command.RedisClient.sendCommand (/srv/node_modules/redis/lib/extendedApi.js:46:26)
at georadiusGeneric (/srv/node_modules/georedis/lib/interfaceNative.js:178:10)
at NativeInterface.georadius (/srv/node_modules/georedis/lib/interfaceNative.js:124:3)
at GeoSet.nearby (/srv/node_modules/georedis/main.js:146:31) )
at new Promise (<anonymous>)
at process._tickCallback (internal/process/next_tick.js:68:7)
command: 'GEORADIUS',
code: 'NR_CLOSED',
args:
[ 'geo',
-87.75563344016012,
41.89034192093163,
10000,
'm' ] }
There's 250K locations saved.
Other simple redis commands works.
Should I consider using another way of storing locations? Any ideas of the cause?
By reducing the radius to 5km it seems to happen less.
I need set coords and a status of user, can I?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.