1 # SPDX-FileCopyrightText: 2015 Eric Larson
3 # SPDX-License-Identifier: Apache-2.0
5 from __future__ import division
7 from datetime import datetime
8 from pip._vendor.cachecontrol.cache import BaseCache
11 class RedisCache(BaseCache):
13 def __init__(self, conn):
17 return self.conn.get(key)
19 def set(self, key, value, expires=None):
21 self.conn.set(key, value)
22 elif isinstance(expires, datetime):
23 expires = expires - datetime.utcnow()
24 self.conn.setex(key, int(expires.total_seconds()), value)
26 self.conn.setex(key, expires, value)
28 def delete(self, key):
32 """Helper for clearing all the keys in a database. Use with
34 for key in self.conn.keys():
38 """Redis uses connection pooling, no need to close the connection."""