Geospatial Indexing with Redis & Sinatra for a Facebook App

匆匆过客 提交于 2019-12-04 14:50:17

I like to avoid multiple platforms and have implemented something similar using redis. Geospatial indexing isn't all that different to indexing anything else in redis. You just need a function to convert lat/long to a single number covering an appropriate area, then you use than number as the key to a set containing all users in that area. If you chose the area right, retrieving that set and possibly some of its neighbours should get you an appropriate number of users to run actual distance calculations on for final filtering/sorting.

The general case of geospatial queries would be quite hard to implement, but you don't need it and redis is the wrong platform for ad hoc queries anyway.

Implementing geospatial indexing in Redis sounds prohibitively time consuming if you think MongoDB is a valid option. Mongo is fast and very nice to work with. If the majority of the queries will be against the geospatial index there is no reason not to use Mongo, in my opinion.

I often find myself using both Mongo and Redis in the same project. They both have very useful properties, and some use cases work really well in Mongo, and some in Redis. However, the converse is also true, some things are really, really hard to get right in Redis, and other things aren't practically possible in Mongo. Geospatial indexes is an example of the former and set operations an example of the latter.

Also, without knowing very much about Sunspot, would it really use Redis? Doesn't it use Solr, which uses the filesystem for storage? It doesn't sound to me like you could get Redis in there, and unless I'm completely wrong I would say that you should definitely go with MongoDB.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!