Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
Use vanilla context manager for utils.pipeline to support 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
seandstewart committed Jan 28, 2021
1 parent 8aa723a commit f046496
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions aioredis/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from contextlib import asynccontextmanager
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -26,11 +25,16 @@ def from_url(url, **kwargs):
return Redis.from_url(url, **kwargs)


@asynccontextmanager
async def pipeline(redis_obj: "Redis") -> "Pipeline":
p = redis_obj.pipeline()
yield p
await p.execute()
class pipeline:
def __init__(self, redis_obj: "Redis"):
self.p: "Pipeline" = redis_obj.pipeline()

async def __aenter__(self) -> "Pipeline":
return self.p

async def __aexit__(self, exc_type, exc_val, exc_tb):
await self.p.execute()
del self.p


def str_if_bytes(value):
Expand Down

0 comments on commit f046496

Please sign in to comment.