| # SPDX-FileCopyrightText: 2015 Eric Larson |
| # SPDX-License-Identifier: Apache-2.0 |
| from __future__ import division |
| from datetime import datetime |
| from pip._vendor.cachecontrol.cache import BaseCache |
| class RedisCache(BaseCache): |
| def __init__(self, conn): |
| return self.conn.get(key) |
| def set(self, key, value, expires=None): |
| self.conn.set(key, value) |
| expires = expires - datetime.utcnow() |
| self.conn.setex(key, int(expires.total_seconds()), value) |
| """Helper for clearing all the keys in a database. Use with |
| for key in self.conn.keys(): |
| """Redis uses connection pooling, no need to close the connection.""" |