refactor: frappe.cache.set_value
redis.set accepts ex kwarg, etc
This commit is contained in:
parent
f2f91d3067
commit
aae0cd896e
1 changed files with 3 additions and 8 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# License: MIT. See LICENSE
|
||||
import pickle
|
||||
import re
|
||||
from contextlib import suppress
|
||||
|
||||
import redis
|
||||
from redis.commands.search import Search
|
||||
|
|
@ -62,14 +63,8 @@ class RedisWrapper(redis.Redis):
|
|||
if not expires_in_sec:
|
||||
frappe.local.cache[key] = val
|
||||
|
||||
try:
|
||||
if expires_in_sec:
|
||||
self.setex(name=key, time=expires_in_sec, value=pickle.dumps(val))
|
||||
else:
|
||||
self.set(key, pickle.dumps(val))
|
||||
|
||||
except redis.exceptions.ConnectionError:
|
||||
return None
|
||||
with suppress(redis.exceptions.ConnectionError):
|
||||
self.set(name=key, value=pickle.dumps(val), ex=expires_in_sec)
|
||||
|
||||
def get_value(self, key, generator=None, user=None, expires=False, shared=False):
|
||||
"""Return cache value. If not found and generator function is
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue