Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/cachecontrol/caches/redis_cache.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author | shellac |
---|---|
date | Mon, 01 Jun 2020 08:59:25 -0400 |
parents | 79f47841a781 |
children |
comparison
equal
deleted
inserted
replaced
4:79f47841a781 | 5:9b1c78e6ba9c |
---|---|
1 from __future__ import division | |
2 | |
3 from datetime import datetime | |
4 | |
5 | |
6 def total_seconds(td): | |
7 """Python 2.6 compatability""" | |
8 if hasattr(td, 'total_seconds'): | |
9 return td.total_seconds() | |
10 | |
11 ms = td.microseconds | |
12 secs = (td.seconds + td.days * 24 * 3600) | |
13 return (ms + secs * 10**6) / 10**6 | |
14 | |
15 | |
16 class RedisCache(object): | |
17 | |
18 def __init__(self, conn): | |
19 self.conn = conn | |
20 | |
21 def get(self, key): | |
22 return self.conn.get(key) | |
23 | |
24 def set(self, key, value, expires=None): | |
25 if not expires: | |
26 self.conn.set(key, value) | |
27 else: | |
28 expires = expires - datetime.now() | |
29 self.conn.setex(key, total_seconds(expires), value) | |
30 | |
31 def delete(self, key): | |
32 self.conn.delete(key) | |
33 | |
34 def clear(self): | |
35 """Helper for clearing all the keys in a database. Use with | |
36 caution!""" | |
37 for key in self.conn.keys(): | |
38 self.conn.delete(key) | |
39 | |
40 def close(self): | |
41 self.conn.disconnect() |