..
This commit is contained in:
parent
b7cdb5bb4e
commit
b6dfd6b41f
|
@ -1,7 +1,7 @@
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import aioredis
|
import aioredis
|
||||||
from aioredis import ConnectionsPool
|
# from aioredis import ConnectionsPool
|
||||||
|
|
||||||
from settings import REDIS_URL
|
from settings import REDIS_URL
|
||||||
|
|
||||||
|
@ -9,23 +9,22 @@ from settings import REDIS_URL
|
||||||
class Redis:
|
class Redis:
|
||||||
def __init__(self, uri=REDIS_URL):
|
def __init__(self, uri=REDIS_URL):
|
||||||
self._uri: str = uri
|
self._uri: str = uri
|
||||||
self._pool: Optional[ConnectionsPool] = None
|
self._instance = None
|
||||||
|
|
||||||
async def connect(self):
|
async def connect(self):
|
||||||
if self._pool is not None:
|
if self._instance is not None:
|
||||||
return
|
return
|
||||||
pool = await aioredis.create_pool(self._uri)
|
self._instance = await aioredis.from_url(self._uri)# .create_pool(self._uri)
|
||||||
self._pool = pool
|
|
||||||
|
|
||||||
async def disconnect(self):
|
async def disconnect(self):
|
||||||
if self._pool is None:
|
if self._instance is None:
|
||||||
return
|
return
|
||||||
self._pool.close()
|
self._instance.close()
|
||||||
await self._pool.wait_closed()
|
await self._instance.wait_closed()
|
||||||
self._pool = None
|
self._instance = None
|
||||||
|
|
||||||
async def execute(self, command, *args, **kwargs):
|
async def execute(self, command, *args, **kwargs):
|
||||||
return await self._pool.execute(command, *args, **kwargs, encoding="UTF-8")
|
return await self._instance.execute(command, *args, **kwargs, encoding="UTF-8")
|
||||||
|
|
||||||
|
|
||||||
async def test():
|
async def test():
|
||||||
|
|
Loading…
Reference in New Issue
Block a user