问题描述
我正在用Sinatra& amp; amp; 进行重建。 Redis和我想要:
- 设置操作以管理请求&用户之间的关系
- 地理空间索引显示附近的应用用户
>当前的Redis实现
每个用户有两个Redis有序集( reqSent
& reqRecv
)存储uid。我们对请求进行排序的 SCORE
是进行请求的 time
(UNIX时间戳)。我使用的是有序集而不是列表,因为用户可能只会将请求类型(rid)编码为数字并预先添加到uid中。 (rid | uid)例如,对于uid = 100的用户,我们可能有:
100:reqSent => [1 | 123,2 | 123,2 | 134]#format:[rid | tid]
100:reqRecv => [3 | 343,5 | 142,4 | 2224]#format:[rid | uid]
,我想我应该如何使用Redis实现地理空间索引?我不知道如何使用Redis来实现地理空间索引。我应该使用(localsolr)吗?显然,您可以使用。
我喜欢避免多个平台,并使用redis实现类似的功能。地理空间索引与redis中其他任何内容的索引并不完全不同。您只需要一个函数将lat / long转换为覆盖适当区域的单个数字,然后将数字用作包含该区域中所有用户的集合的关键字。如果您选择了正确的区域,那么检索该集合以及可能的一些邻居应该为您提供适当数量的用户来运行实际距离计算以进行最终过滤/排序。
地理空间查询的一般情况很难实现,但你不需要它,而redis也是特别查询的错误平台。
I'm rebuilding Lovers on Facebook with Sinatra & Redis, and I want:
- Set operations for managing requests & relationships between users
- Geospatial indexing to display nearby app users
Current Redis Implementation
Each user has two Redis ordered sets (reqSent
& reqRecv
) that store uids. The SCORE
that we order the requests by is the time
(UNIX timestamp) the request was made. I am using ordered sets instead of lists because a user may only make The request type (rid) is encoded as a number and prepended to the uid. (rid|uid) E.g., for the user with uid=100, we might have:
100:reqSent => ["1|123", "2|123", "2|134"] # format: ["rid|tid"]
100:reqRecv => ["3|343", "5|142", "4|2224"] # format: ["rid|uid"]
MongoDB supports geospatial indexing natively, so I'm thinking of switching to that.
Otherwise, how should I implement geospatial indexing with Redis? Should I do it with Sunspot (localsolr)? Apparently, you can use Sunspot with Redis.
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.
这篇关于使用Redis的地理空间索引& Sinatra为Facebook应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!