utils.py 666 B

123456789101112131415161718192021222324252627282930313233
  1. from contextlib import contextmanager
  2. try:
  3. import hiredis
  4. HIREDIS_AVAILABLE = True
  5. except ImportError:
  6. HIREDIS_AVAILABLE = False
  7. def from_url(url, db=None, **kwargs):
  8. """
  9. Returns an active Redis client generated from the given database URL.
  10. Will attempt to extract the database id from the path url fragment, if
  11. none is provided.
  12. """
  13. from redis.client import Redis
  14. return Redis.from_url(url, db, **kwargs)
  15. @contextmanager
  16. def pipeline(redis_obj):
  17. p = redis_obj.pipeline()
  18. yield p
  19. p.execute()
  20. class dummy(object):
  21. """
  22. Instances of this class can be used as an attribute container.
  23. """
  24. pass