You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

redis_cache.py 856B

123456789101112131415161718192021222324252627282930313233
  1. from __future__ import division
  2. from datetime import datetime
  3. from pip._vendor.cachecontrol.cache import BaseCache
  4. class RedisCache(BaseCache):
  5. def __init__(self, conn):
  6. self.conn = conn
  7. def get(self, key):
  8. return self.conn.get(key)
  9. def set(self, key, value, expires=None):
  10. if not expires:
  11. self.conn.set(key, value)
  12. else:
  13. expires = expires - datetime.utcnow()
  14. self.conn.setex(key, int(expires.total_seconds()), value)
  15. def delete(self, key):
  16. self.conn.delete(key)
  17. def clear(self):
  18. """Helper for clearing all the keys in a database. Use with
  19. caution!"""
  20. for key in self.conn.keys():
  21. self.conn.delete(key)
  22. def close(self):
  23. """Redis uses connection pooling, no need to close the connection."""
  24. pass