Skip to content

Commit a1a333c

Browse files
committed
feat: add cache intellisense and return types
1 parent 39a4349 commit a1a333c

File tree

3 files changed

+423
-19
lines changed

3 files changed

+423
-19
lines changed

examples.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,15 @@ def add_cache():
195195

196196
result = hyper.cache.add(key="movie-5000", value=movie, ttl="1w")
197197
print("hyper.cache.add result --> ", result)
198-
# hyper.cache.add result --> {'ok': True, 'status': 201}
198+
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
199+
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}
200+
201+
202+
def get_cache():
203+
key = "movie-5000"
204+
result: HyperGetResult = hyper.cache.get_async(key)
205+
print("hyper.cache.get_async result --> ", result)
206+
# hyper.cache.get_async result --> {'_id': 'movie-5000', 'type': 'movie', 'title': 'Back to the Future 2', 'year': '1987', 'status': 200}
199207

200208

201209
def remove_cache():

examples_async.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
HyperGetResult,
1010
IdResult,
1111
ListOptions,
12-
OKIdResult,
12+
OkIdResult,
1313
QueryOptions,
1414
Result,
1515
SearchQueryOptions,
@@ -209,11 +209,37 @@ async def add_cache():
209209
"year": "1987",
210210
}
211211

212-
result = await hyper.cache.add_async(
213-
key="movie-5000", value=movie, ttl="1w"
212+
result: Result = await hyper.cache.add_async(
213+
key="movie-5000", value=movie, ttl="24h"
214214
)
215215
print("hyper.cache.add_async result --> ", result)
216-
# hyper.cache.add_async result --> {'ok': True, 'status': 201}
216+
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
217+
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}
218+
219+
220+
async def add_cache_thing():
221+
thing: Dict = {"likes": 100}
222+
223+
result: Result = await hyper.cache.add_async(
224+
key="thing-1", value=thing, ttl="1m"
225+
)
226+
print("hyper.cache.add_async result --> ", result)
227+
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
228+
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}
229+
230+
231+
async def get_cache():
232+
key = "movie-5000"
233+
result: HyperGetResult = await hyper.cache.get_async(key)
234+
print("hyper.cache.get_async result --> ", result)
235+
# hyper.cache.get_async result --> {'_id': 'movie-5000', 'type': 'movie', 'title': 'Back to the Future 2', 'year': '1987', 'status': 200}
236+
237+
238+
async def get_cache_thing():
239+
key: str = "thing-1"
240+
result: HyperGetResult = await hyper.cache.get_async(key)
241+
print("hyper.cache.get_async result --> ", result)
242+
# hyper.cache.get_async result --> {'likes': 100, 'status': 200}
217243

218244

219245
async def remove_cache():
@@ -239,12 +265,12 @@ async def update_cache():
239265

240266

241267
async def query_cache():
242-
result = await hyper.cache.query_async(pattern="movie-500*")
268+
result: HyperDocsResult = await hyper.cache.query_async(
269+
pattern="movie-500*"
270+
)
243271
print("hyper.cache.query_async result --> ", result)
244272
# hyper.cache.query_async result --> {'docs': [{'key': 'movie-5001', 'value': {'_id': 'movie-5001', 'type': 'movie', 'title': 'Back to the Future 3', 'year': '1989'}}, {'key': 'movie-5000', 'value': {'_id': 'movie-5000', 'type': 'movie', 'title': 'Back to the Future 2', 'year': '1988'}}], 'ok': True, 'status': 200}
245273

246-
hyper.search.update(key, doc)
247-
248274

249275
############################
250276
#

0 commit comments

Comments
 (0)