Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async support #263

Open
databasedav opened this issue Sep 26, 2020 · 11 comments
Open

async support #263

databasedav opened this issue Sep 26, 2020 · 11 comments

Comments

@databasedav
Copy link

databasedav commented Sep 26, 2020

This is a bump for these 2 old issues #51, #52.

Based on this comment #52 (comment), it sounds like async C support was the prereq for adding async python support which seems to have been added a few months ago. Has there been any progress on async python support? Thanks!

@rbotzer
Copy link
Member

rbotzer commented Aug 26, 2021

This is on the way for the next version of the Python client.

@leos
Copy link

leos commented Nov 18, 2021

That's great to hear @rbotzer - any ETA on that release? It looks like it's been quite a while since 6.0.0.

@riteshpallod
Copy link

is there any update on this ?

@dimaqq
Copy link
Contributor

dimaqq commented Jan 31, 2022

🙏🏿

@dimaqq
Copy link
Contributor

dimaqq commented Jan 5, 2023

Poke 🖤

@KimSoungRyoul
Copy link

🙏🏿

@KimSoungRyoul
Copy link

is there any update? since #462

Looking forward to async support 🙏

P.S. I always thanks to Aerospike Team for great opensource

@Lior-Balabanovsky-Forter

Hey, is there any update?

@dimaqq
Copy link
Contributor

dimaqq commented Nov 7, 2024

In all likelihood, someone will develop a new database, written in, say, rust with native, say, rust bindings and then it will be trivial to map those to Python.

@databasedav
Copy link
Author

the new client will be a layer on top of a rust base, see aerospike/aerospike-client-rust#147 (comment)

in the meantime, simply make all aerospike calls in a thread pool, which is what i've been doing since asking this question, here's the code, which is on python 3.9, but should be easy to upgrade

class AerospikeClient:
    def __init__(self, address):
        self._address = address

    async def connect(self) -> None:
        hosts = list()
        for addr in self._address.split(','):
            host, port = addr.split(':')
            hosts.append((host, int(port)))
        connect_args = dict()
        if username := os.getenv('AEROSPIKE_USERNAME'):
            connect_args['user'] = username
            connect_args['policies'] = {'auth_mode': aerospike.AUTH_INTERNAL},
            connect_args['password'] = os.getenv('AEROSPIKE_PASSWORD')
        if len(hosts) > 1:
            connect_args['shm'] = {}
        self._aerospike = aerospike.client({
            'hosts': hosts,
            'use_shared_connection': True,
            **connect_args
        })
        # TODO: can get rid of this when client is async
        class async_aerospike:
            def __init__(self, a):
                self._aerospike = a
                self._loop = None

            @property
            def loop(self):
                if not self._loop:
                    self._loop = asyncio.get_running_loop()
                return self._loop

            def __getattr__(self, attr: str):
                async def meth(*args, **kwargs):
                    return await self.loop.run_in_executor(
                        None,
                        functools.partial(
                            getattr(self._aerospike, attr), *args, **kwargs
                        ),
                    )
                return meth
        self.aerospike: aerospike.Client = async_aerospike(self._aerospike)
        await self.aerospike.connect()

    async def disconnect(self) -> None:
        await self.aerospike.close()

    @property
    def connected(self) -> bool:
        return self._aerospike.is_connected()

    def __getattr__(self, attr: str):
        return getattr(self.aerospike, attr)

@juliannguyen4
Copy link
Collaborator

Async support is not coming in 2024 and we don’t have a delivery date scheduled yet, but we will respond back again once we solidify our 2025 roadmap

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants