-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.py
More file actions
31 lines (27 loc) · 913 Bytes
/
cache.py
File metadata and controls
31 lines (27 loc) · 913 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Cache:
def __init__(self, client):
self.client = client
def set(self, key, value):
"""
把需要被缓存的数据存储到键key里面,如果键key已经有值,那么使用新值去覆盖旧值
:param key:
:param value:
:return:
"""
self.client.set(key, value)
def get(self, key):
"""
获取存储在键key里面的缓存数据,如果key不存在,那么返回None
:param key:
:return:
"""
return self.client.get(key)
def update(self, key, new_value):
"""
对键key存储的缓存数据进行更新,并返回键key在被更新之前存储的缓存数据。
如果键key之前并没有存储数据,那么返回None
:param key:
:param new_value:
:return:
"""
return self.client.getset(key, new_value)