"Location": "RCP", } await conn.set_hash("user", user) if await conn.exists("user"): print(await conn.get_hash("user")) await conn.delete("user") for lp in range(10000): print(f'Test number {lp}') async with await rd.acquire() as conn: await conn.ping() await conn.execute("set", "Test1", "UltraTest") await conn.delete("Test1") print('Ending ...') try: print("Connected: {}".format(rd.is_connected())) with rd as conn: loop.run_until_complete(conn.execute("set", "my-key", "UltraValue")) value = loop.run_until_complete(conn.execute("get", "my-key")) print("raw value:", value) # adquire a new connection (with pool) r = loop.run_until_complete(rd.acquire()) loop.run_until_complete(r.execute("set", "my-key", "UltraKey")) value = loop.run_until_complete(r.execute("get", "my-key")) print("new value:", value) loop.run_until_complete(test_redis(r)) finally: loop.run_until_complete(rd.close()) loop.close()
loop = asyncio.new_event_loop() loop.set_exception_handler(default_exception_handler) params = { "user": "******", "password": "******", "host": "127.0.0.1", "port": "5432", "database": "navigator_dev", "DEBUG": True, } pool = AsyncPool('pg', loop=loop, params=params) loop.run_until_complete(pool.connect()) db = loop.run_until_complete(pool.acquire()) print('Pool Connected: ', pool.is_connected()) db = loop.run_until_complete(pool.acquire()) print('Is Connected: ', db.is_connected()) loop.run_until_complete(db.test_connection()) try: print('CREATION of MODEL::') mdl = QueryUtil(**{"query_slug": "walmart_stores"}) mdl.Meta.set_connection(db) result = loop.run_until_complete(mdl.fetch(raw_query=False)) print('RESULT IS: ', result) mdl = QueryUtil(**{"program_slug": "walmart", "provider": "db"}) mdl.Meta.set_connection(loop.run_until_complete(pool.acquire()))
OIDS=FALSE ); ALTER TABLE test.stores OWNER TO "troc-pgdata"; """ import asyncio loop = asyncio.get_event_loop() asyncio.set_event_loop(loop) asyncpg_url = "postgres://*****:*****@127.0.0.1:5432/navigator_dev" pool = AsyncPool("pg", dsn=asyncpg_url, loop=loop) loop.run_until_complete(pool.connect()) db = loop.run_until_complete(pool.acquire()) loop.run_until_complete(pool.release(connection=db.get_connection())) print(db, type(db)) result = loop.run_until_complete(pool.execute("SELECT 1")) print(result) def adb(): #loop = asyncio.get_event_loop() db = None if pool.is_connected(): #db = asyncio.get_running_loop().run_until_complete(dbpool.acquire()) db = loop.run_until_complete(pool.acquire()) return asyncORM(db=db)