Skip to content

Commit

Permalink
feat: add cache intellisense and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
tripott committed Jun 9, 2022
1 parent 39a4349 commit a1a333c
Show file tree
Hide file tree
Showing 3 changed files with 423 additions and 19 deletions.
10 changes: 9 additions & 1 deletion examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@ def add_cache():

result = hyper.cache.add(key="movie-5000", value=movie, ttl="1w")
print("hyper.cache.add result --> ", result)
# hyper.cache.add result --> {'ok': True, 'status': 201}
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}


def get_cache():
key = "movie-5000"
result: HyperGetResult = hyper.cache.get_async(key)
print("hyper.cache.get_async result --> ", result)
# hyper.cache.get_async result --> {'_id': 'movie-5000', 'type': 'movie', 'title': 'Back to the Future 2', 'year': '1987', 'status': 200}


def remove_cache():
Expand Down
40 changes: 33 additions & 7 deletions examples_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
HyperGetResult,
IdResult,
ListOptions,
OKIdResult,
OkIdResult,
QueryOptions,
Result,
SearchQueryOptions,
Expand Down Expand Up @@ -209,11 +209,37 @@ async def add_cache():
"year": "1987",
}

result = await hyper.cache.add_async(
key="movie-5000", value=movie, ttl="1w"
result: Result = await hyper.cache.add_async(
key="movie-5000", value=movie, ttl="24h"
)
print("hyper.cache.add_async result --> ", result)
# hyper.cache.add_async result --> {'ok': True, 'status': 201}
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}


async def add_cache_thing():
thing: Dict = {"likes": 100}

result: Result = await hyper.cache.add_async(
key="thing-1", value=thing, ttl="1m"
)
print("hyper.cache.add_async result --> ", result)
# OkResult - hyper.cache.add result --> {'ok': True, 'status': 201}
# NotOkResult - hyper.cache.add result --> {'ok': False, 'status': 409, 'msg': 'Document Conflict'}


async def get_cache():
key = "movie-5000"
result: HyperGetResult = await hyper.cache.get_async(key)
print("hyper.cache.get_async result --> ", result)
# hyper.cache.get_async result --> {'_id': 'movie-5000', 'type': 'movie', 'title': 'Back to the Future 2', 'year': '1987', 'status': 200}


async def get_cache_thing():
key: str = "thing-1"
result: HyperGetResult = await hyper.cache.get_async(key)
print("hyper.cache.get_async result --> ", result)
# hyper.cache.get_async result --> {'likes': 100, 'status': 200}


async def remove_cache():
Expand All @@ -239,12 +265,12 @@ async def update_cache():


async def query_cache():
result = await hyper.cache.query_async(pattern="movie-500*")
result: HyperDocsResult = await hyper.cache.query_async(
pattern="movie-500*"
)
print("hyper.cache.query_async result --> ", result)
# 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}

hyper.search.update(key, doc)


############################
#
Expand Down
Loading

0 comments on commit a1a333c

Please sign in to comment.