redis-om-python
redis-om-python copied to clipboard
Implement GEO querying
Implement GEO query in Hash model and JSON as supported.
This would be a great enhancement. When is this planned?
Any tips on how to contribute to this enhancement? I am currently working with geospatial queries. And I'd love to combine by queries together in one go.
# Adding a user's location to Redis
async def add_user_location(pk: str, lat: float, lon: float) -> None:
'''
Adds the user's location to the redis database
'''
redis = RedisUser.db()
await redis.geoadd('Users', (lon, lat, pk))
# Getting nearby users in Redis
async def get_nearby_users(pk: str, radius: int, unit: str) -> List[str]:
'''
Gets the nearby users in the redis database
'''
redis = RedisUser.db()
return await redis.georadiusbymember("Users", pk, radius, unit)
This is my usecase:
async def get_users_by_location(self, pk: str, radius: int, unit: str) -> List[User]:
"""This function gets all nearby users for a given user in a certain radius"""
list_of_pk = await get_nearby_users(pk, radius, unit)
list_of_users = []
for pk in list_of_pk:
list_of_users.append(await RedisUser.get(pk.decode('utf-8'))) # type: ignore
return list_of_users
I'd like to change things on redis-om side instead of sending multiple DB queries.