redis-om-python icon indicating copy to clipboard operation
redis-om-python copied to clipboard

Implement GEO querying

Open simonprickett opened this issue 2 years ago • 2 comments

Implement GEO query in Hash model and JSON as supported.

simonprickett avatar Jan 21 '22 16:01 simonprickett

This would be a great enhancement. When is this planned?

XChikuX avatar Jan 09 '23 11:01 XChikuX

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.

XChikuX avatar May 16 '23 06:05 XChikuX