Skip to content

Commit b2101d3

Browse files
committed
Merge pull request #373 from sirnicolaz/sugar
Add utility for pipelining within 'with' statement.
2 parents 271da6e + 89454b1 commit b2101d3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

redis/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from contextlib import contextmanager
2+
3+
14
try:
25
import hiredis
36
HIREDIS_AVAILABLE = True
@@ -14,3 +17,10 @@ def from_url(url, db=None, **kwargs):
1417
"""
1518
from redis.client import Redis
1619
return Redis.from_url(url, db, **kwargs)
20+
21+
22+
@contextmanager
23+
def pipeline(redis_obj):
24+
p = redis_obj.pipeline()
25+
yield p
26+
p.execute()

0 commit comments

Comments
 (0)